Skip to content

Commit 729609d

Browse files
committed
New slab indicator
1 parent fe4df8f commit 729609d

File tree

6 files changed

+202
-0
lines changed

6 files changed

+202
-0
lines changed

src/indicators/Slab/Slab.scss

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
@use "../../scss/variables" as defaults;
2+
3+
$slabWidth: 4em;
4+
5+
.slab-bounding-box {
6+
$boundingWidth: 7em;
7+
font-size: defaults.$fontSizer;
8+
color: defaults.$defaultColor;
9+
position: relative;
10+
11+
width: $boundingWidth;
12+
height: calc($boundingWidth / 1.489);
13+
display: flex;
14+
justify-content: flex-end;
15+
align-items: flex-end;
16+
17+
.slab-text {
18+
position: absolute;
19+
top: 105%;
20+
left: 50%;
21+
transform: translateX(-50%);
22+
color: currentColor;
23+
font-size: 0.7em;
24+
// font-weight: 600;
25+
}
26+
27+
.slab-loader {
28+
width: $slabWidth;
29+
height: $slabWidth;
30+
transform: perspective(15em) rotateX(66deg) rotateZ(-25deg);
31+
transform-style: preserve-3d;
32+
margin-bottom: -1.3em;
33+
34+
.slab {
35+
position: absolute;
36+
width: $slabWidth;
37+
height: $slabWidth;
38+
background: currentColor;
39+
opacity: 0;
40+
box-shadow: -0.08em 0.15em 0 rgb(0 0 0 / 45%);
41+
transform-origin: 50% 0%;
42+
-webkit-animation: slabMove 4s linear infinite;
43+
animation: slabMove 4s linear infinite;
44+
45+
&:nth-child(1) {
46+
animation-delay: 0s;
47+
}
48+
&:nth-child(2) {
49+
animation-delay: 1s;
50+
}
51+
&:nth-child(3) {
52+
animation-delay: 2s;
53+
}
54+
&:nth-child(4) {
55+
animation-delay: 3s;
56+
}
57+
}
58+
}
59+
}
60+
61+
@keyframes slabMove {
62+
0% {
63+
transform: translateY(0) rotateX(30deg);
64+
opacity: 0;
65+
}
66+
10% {
67+
transform: translateY(-48%);
68+
opacity: 1;
69+
}
70+
90% {
71+
transform: translateY(-422%);
72+
opacity: 0.1;
73+
}
74+
100% {
75+
transform: translateY(-480%);
76+
opacity: 0;
77+
}
78+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
import { ComponentStory, ComponentMeta } from "@storybook/react";
3+
import { Slab } from "./Slab";
4+
5+
export default {
6+
title: "rli/Slab",
7+
component: Slab
8+
} as ComponentMeta<typeof Slab>;
9+
10+
const Template: ComponentStory<typeof Slab> = args => <Slab {...args} />;
11+
12+
export const Primary = Template.bind({});
13+
14+
export const Secondary = Template.bind({});
15+
Secondary.args = {
16+
color: "#b7ac9a",
17+
text: true
18+
};
19+
20+
export const Small = Template.bind({});
21+
Small.args = {
22+
size: "small"
23+
};
24+
25+
export const Medium = Template.bind({});
26+
Medium.args = {
27+
size: "medium"
28+
};
29+
30+
export const Large = Template.bind({});
31+
Large.args = {
32+
size: "large"
33+
};

src/indicators/Slab/Slab.tsx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"use strict";
2+
3+
import React from "react";
4+
5+
import { SlabProps } from "./Slab.types";
6+
import "./Slab.scss";
7+
import useFontsizeMapper from "../../hooks/useFontsizeMapper";
8+
9+
const Slab = (props: SlabProps) => {
10+
// Styles
11+
let styles: React.CSSProperties = Object(props?.style);
12+
13+
/* Size SETTINGS */
14+
let fontSize: string | number = useFontsizeMapper(props?.size);
15+
16+
// Setting size by specifying font-size in style attr
17+
// and modifying styles to exclude fontSize
18+
if (props?.style?.fontSize) {
19+
const { fontSize: cssFontSize, ...css } = props?.style;
20+
21+
styles = css;
22+
fontSize = cssFontSize;
23+
}
24+
25+
/* Color SETTINGS */
26+
// If Color property is a string, that is the color of all rings
27+
// If color property is an array, that is color for each rings
28+
const slabColor: string | string[] = props?.color ?? "";
29+
const slabColorStyles: React.CSSProperties =
30+
slabColor instanceof Array
31+
? { ...genStyleFromColorArr(slabColor) }
32+
: { ...genStyleFromColorStr(slabColor) };
33+
34+
return (
35+
<span
36+
className="rli-d-i-b slab-bounding-box"
37+
style={{ ...(fontSize && { fontSize }), ...slabColorStyles, ...styles }}
38+
>
39+
<span className="rli-d-i-b slab-loader slabs">
40+
<span className="slab"></span>
41+
<span className="slab"></span>
42+
<span className="slab"></span>
43+
<span className="slab"></span>
44+
</span>
45+
<span
46+
className="rli-d-i-b rli-text-format slab-text"
47+
style={{
48+
...(props?.textColor && {
49+
color: props?.textColor,
50+
mixBlendMode: "unset"
51+
})
52+
}}
53+
>
54+
{props?.text
55+
? typeof props?.text === "string" && props?.text.length
56+
? props?.text
57+
: "loading"
58+
: null}
59+
</span>
60+
</span>
61+
);
62+
};
63+
64+
export { Slab };
65+
66+
function genStyleFromColorStr(
67+
colorStr: string | undefined
68+
): React.CSSProperties {
69+
colorStr = colorStr ?? "";
70+
71+
const stylesObject: any = {};
72+
73+
stylesObject["color"] = colorStr;
74+
75+
return stylesObject;
76+
}
77+
78+
function genStyleFromColorArr(colorArr: string[]): React.CSSProperties {
79+
const stylesObject: any = {};
80+
81+
// NOT supporting Individual bubble coloring
82+
const [color] = colorArr;
83+
84+
stylesObject["color"] = color;
85+
86+
return stylesObject;
87+
}

src/indicators/Slab/Slab.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { CommonProps } from "../common.types";
2+
export interface SlabProps extends CommonProps {}

src/indicators/Slab/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Slab } from "./Slab";

src/indicators/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export * from "./Riple";
99
export * from "./Seek";
1010
export * from "./GlidingBlink";
1111
export * from "./Twist";
12+
export * from "./Slab";
1213

1314
export { CircularProgress as default };

0 commit comments

Comments
 (0)