Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spinner: VR implementation changes #3774

Merged
merged 12 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/gestalt-design-tokens/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ function getSources({ theme, modeTheme, platform, language }) {
'tokens/vr-theme/sema/space.json',
`tokens/vr-theme/sema/text/language/${language}.json`,
'tokens/vr-theme/sema/motion.json',
'tokens/vr-theme/comp/spinner.json',
...(theme === 'vr-theme-web-mapping'
? [
`tokens/vr-theme-web-mapping/base-color-dataviz-${modeTheme}.json`,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,19 @@
}
}
},
"spinner": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove these ones

"color": {
"pink": {
"value": "#d452d1"
},
"orange": {
"value": "#ff7c36"
},
"blue": {
"value": "#24ccb0"
}
}
},
"switch": {
"default": {
"selected": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,19 @@
}
}
},
"spinner": {
"color": {
"pink": {
"value": "#d452d1"
},
"orange": {
"value": "#ff7c36"
},
"blue": {
"value": "#24ccb0"
}
}
},
"switch": {
"default": {
"selected": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@
}
}
},
"spinner": {
"color": {
"pink": {
"value": "{comp.spinner.color.pink}"
},
"orange": {
"value": "{comp.spinner.color.orange}"
},
"blue": {
"value": "{comp.spinner.color.blue}"
}
}
},
"switch": {
"default": {
"unselected": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,19 @@
}
}
},
"spinner": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you dont need this either

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 - the VR tokens will be pulled in here

"color": {
"pink": {
"value": "{comp.spinner.color.pink}"
},
"orange": {
"value": "{comp.spinner.color.orange}"
},
"blue": {
"value": "{comp.spinner.color.blue}"
}
}
},
"switch": {
"default": {
"unselected": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"comp": {
diyorbek marked this conversation as resolved.
Show resolved Hide resolved
"spinner": {
"color": {
"pink": {
"type": "color",
"value": "#d452d1"
},
"orange": {
"type": "color",
"value": "#ff7c36"
},
"blue": {
"type": "color",
"value": "#24ccb0"
}
}
}
}
}
14 changes: 14 additions & 0 deletions packages/gestalt/src/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Box from './Box';
import { useDefaultLabelContext } from './contexts/DefaultLabelProvider';
import Icon from './Icon';
import styles from './Spinner.css';
import VRSpinner from './Spinner/VRSpinner';
import useInExperiment from './useInExperiment';

const SIZE_NAME_TO_PIXEL = {
sm: 32,
Expand Down Expand Up @@ -46,6 +48,18 @@ export default function Spinner({
size = 'md',
}: Props) {
const { accessibilityLabel: accessibilityLabelDefault } = useDefaultLabelContext('Spinner');

const isInVRExperiment = useInExperiment({
webExperimentName: 'web_gestalt_visualRefresh',
mwebExperimentName: 'web_gestalt_visualRefresh',
});

if (isInVRExperiment) {
return (
<VRSpinner accessibilityLabel={accessibilityLabel} delay={delay} show={show} size={size} />
);
}

return show ? (
<Box display="flex" justifyContent="around" overflow="hidden">
<div className={classnames(styles.icon, { [styles.delay]: delay })}>
Expand Down
94 changes: 94 additions & 0 deletions packages/gestalt/src/Spinner/VRSpinner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
.spinner {
--g-size: 40px;
--g-dot-size: calc(var(--g-size) / 3);
--g-dot-space: calc(var(--g-dot-size) * 1.75);

height: var(--g-size);
width: var(--g-size);
}

.spinnerFrame {
animation: spin 1500ms linear infinite;
box-sizing: border-box;
height: calc(var(--g-dot-space) * sqrt(3) / 2);
left: calc(var(--g-dot-size) * 0.625);
position: relative;
top: calc(var(--g-dot-size) / 2);
transform-origin: center calc(var(--g-dot-space) / sqrt(3));
width: var(--g-dot-space);
}

.spinnerFrame > div {
animation-composition: add;
animation-duration: 800ms, 1.8s;
animation-iteration-count: infinite;
animation-name: scale, colors;
animation-timing-function: linear;
border-radius: 50%;
diyorbek marked this conversation as resolved.
Show resolved Hide resolved
height: var(--g-dot-size);
position: absolute;
width: var(--g-dot-size);
}

.dot1 {
animation-delay: 0s;
left: 50%;
top: 0;
transform: translate3d(-50%, -50%, 0);
}

.dot2 {
animation-delay: 100ms, 0s;
diyorbek marked this conversation as resolved.
Show resolved Hide resolved
bottom: 0;
diyorbek marked this conversation as resolved.
Show resolved Hide resolved
left: 0;
transform: translate3d(-50%, 50%, 0);
}

.dot3 {
animation-delay: 200ms, 0s;
bottom: 0;
right: 0;
transform: translate3d(50%, 50%, 0);
}

.spinner.delay .spinnerFrame > div {
animation-delay: 300ms;
}

.delay {
animation-delay: 300ms;
}

@keyframes spin {
to {
transform: rotate(360deg);
}
}

@keyframes scale {
50% {
transform: scale(0.8);
}

100% {
transform: scale(1);
}
}

@keyframes colors {
0% {
background-color: var(--color-background-spinner-color-pink);
diyorbek marked this conversation as resolved.
Show resolved Hide resolved
}

33.333% {
background-color: var(--color-background-spinner-color-orange);
}

66.666% {
background-color: var(--color-background-spinner-color-blue);
}

100% {
background-color: var(--color-background-spinner-color-pink);
}
}
45 changes: 45 additions & 0 deletions packages/gestalt/src/Spinner/VRSpinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import classnames from 'classnames';
import styles from './VRSpinner.css';
import Box from '../Box';
import { useDefaultLabelContext } from '../contexts/DefaultLabelProvider';

const SIZE_NAME_TO_PIXEL = {
sm: 32,
md: 40,
lg: 48,
} as const;

type Props = {
accessibilityLabel?: string;
delay?: boolean;
show: boolean;
size?: 'sm' | 'md' | 'lg';
};

export default function Spinner({ accessibilityLabel, delay = true, show, size = 'md' }: Props) {
const { accessibilityLabel: accessibilityLabelDefault } = useDefaultLabelContext('Spinner');

if (!show) return null;

return (
<Box display="flex" justifyContent="around">
<div
aria-label={accessibilityLabel ?? accessibilityLabelDefault}
className={classnames(styles.spinner, styles[size], { [styles.delay]: delay })}
style={
{
'--g-size': `${SIZE_NAME_TO_PIXEL[size]}px`,
} as React.CSSProperties
}
>
<div className={styles.spinnerFrame}>
<div className={styles.dot1} />
<div className={styles.dot2} />
<div className={styles.dot3} />
</div>
</div>
</Box>
);
}

Spinner.displayName = 'Spinner';
Loading
Loading