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

IconButton: VR Certification Fixes #3879

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions docs/examples/iconbutton/enabled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ export default function Example() {
<Flex alignItems="center" gap={8} height="100%" justifyContent="center" width="100%" wrap>
<IconButton accessibilityLabel="Share" bgColor="gray" icon="share" label="gray" size="xl" />
<IconButton
accessibilityLabel="Share"
accessibilityLabel="lightGray"
bgColor="lightGray"
icon="share"
label="lightGray"
size="xl"
/>
<IconButton accessibilityLabel="Share" bgColor="red" icon="share" label="red" size="xl" />
<IconButton
accessibilityLabel="Share"
accessibilityLabel="transparent"
bgColor="transparent"
icon="share"
label="red"
label="transparent"
size="xl"
/>
<IconButton
accessibilityLabel="Share"
accessibilityLabel="transparentDarkGray"
bgColor="transparentDarkGray"
icon="share"
label="transparentDarkGray"
size="xl"
/>
<IconButton
accessibilityLabel="Share"
accessibilityLabel="washLight"
bgColor="washLight"
icon="share"
label="washLight"
size="xl"
/>
<IconButton accessibilityLabel="Share" bgColor="white" icon="share" label="white" size="xl" />
<IconButton accessibilityLabel="white" bgColor="white" icon="share" label="white" size="xl" />
</Flex>
);
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,12 @@
"value": "#1f1f1f"
},
"disabled": {
"value": "{color.background.secondary.base.value}"
"default": {
"value": "{color.background.secondary.base.value}"
},
"selected": {
"value": "{color.background.secondary.base.value}"
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,25 @@
}
}
},
"semitransparentdark": {
"default": {
"value": "{sema.color.background.wash.dark.value}"
},
"hover": {
"value": "{sema.color.hover.background.wash.dark.value}"
},
"active": {
"value": "{sema.color.pressed.background.wash.dark.value}"
},
"disabled": {
"value": "#00000064"
"iconbutton": {
"semitransparentdark": {
"default": {
"value": "{sema.color.background.wash.dark.value}"
},
"hover": {
"value": "{sema.color.hover.background.wash.dark.value}"
},
"active": {
"value": "{sema.color.pressed.background.wash.dark.value}"
},
"disabled": {
"default": {
"value": "#00000064"
},
"selected": {
"value": "{sema.color.background.disabled.value}"
}
}
}
},
"switch": {
Expand Down
4 changes: 4 additions & 0 deletions packages/gestalt/src/IconButton/InternalIconButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
opacity: 0.5;
}

.disabledVr {
cursor: default;
}

.activeText div {
/* Ensure the disabled color is used */
/* stylelint-disable-next-line declaration-no-important */
Expand Down
9 changes: 8 additions & 1 deletion packages/gestalt/src/IconButton/InternalIconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import touchableStyles from '../TapArea.css';
import TextUI from '../TextUI';
import Tooltip from '../Tooltip';
import useFocusVisible from '../useFocusVisible';
import useInExperiment from '../useInExperiment';
import useTapFeedback from '../useTapFeedback';
import { Indexable } from '../zIndex';

Expand Down Expand Up @@ -86,6 +87,10 @@ const InternalIconButtonWithForwardRef = forwardRef<HTMLButtonElement, Props>(fu
// that renders <IconButton ref={inputRef} /> to call inputRef.current.focus()
// @ts-expect-error - TS2322 - Type 'HTMLButtonElement | null' is not assignable to type 'HTMLButtonElement'.
useImperativeHandle(ref, () => innerRef.current);
const isInVRExperiment = useInExperiment({
webExperimentName: 'web_gestalt_visualRefresh',
mwebExperimentName: 'web_gestalt_visualRefresh',
});

const {
compressStyle,
Expand Down Expand Up @@ -121,7 +126,8 @@ const InternalIconButtonWithForwardRef = forwardRef<HTMLButtonElement, Props>(fu
});

const divStyles = classnames(styles.button, touchableStyles.tapTransition, {
[styles.disabled]: disabled,
[styles.disabled]: disabled && !isInVRExperiment,
[styles.disabledVr]: disabled && isInVRExperiment,
[styles.enabled]: !disabled,
[touchableStyles.tapCompress]: !disabled && isTapping,
});
Expand Down Expand Up @@ -172,6 +178,7 @@ const InternalIconButtonWithForwardRef = forwardRef<HTMLButtonElement, Props>(fu
active={!disabled && isActive}
bgColor={bgColor}
dangerouslySetSvgPath={dangerouslySetSvgPath}
disabled={disabled}
focusColor={focusColor}
focused={!disabled && isFocusVisible && isFocused}
hovered={!disabled && isHovered}
Expand Down
16 changes: 15 additions & 1 deletion packages/gestalt/src/Pog.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
border-radius: var(--rounding-400);
}

.rounding500 {
border-radius: var(--rounding-500);
}

.roundingCircle {
border-radius: var(--rounding-circle);
}
Expand Down Expand Up @@ -75,6 +79,10 @@

/* COLORS */

.semitransparent svg {
opacity: 0.4;
}

.red {
background-color: var(--color-background-button-primary-default);
}
Expand Down Expand Up @@ -208,7 +216,13 @@

.transparentDarkGray.disabled {
background-color: var(
--color-background-iconbutton-semitransparentdark-disabled
--color-background-iconbutton-semitransparentdark-disabled-default
);
}

.transparentDarkGray.disabled.selected {
background-color: var(
--color-background-iconbutton-semitransparentdark-disabled-selected
);
}

Expand Down
33 changes: 28 additions & 5 deletions packages/gestalt/src/Pog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Props = {
/**
* See the [rounding](https://gestalt.pinterest.systems/web/pog#Rounding) variant for more info.
*/
rounding?: '0' | '100' | '200' | '300' | '400' | 'circle';
rounding?: '0' | '100' | '200' | '300' | '400' | '500' | 'circle';
/**
* Indicate if Pog is in a selected state. See [States](https://gestalt.pinterest.systems/web/pog#States) for more details.
*/
Expand Down Expand Up @@ -111,7 +111,7 @@ export default function Pog({
xs: 6,
sm: 6,
md: 10,
lg: 14,
eniomoura marked this conversation as resolved.
Show resolved Hide resolved
lg: 12,
xl: 20,
}
: {
Expand All @@ -138,6 +138,7 @@ export default function Pog({
light: 'light',
red: 'error',
white: 'inverse',
disabled: 'disabled',
} as const;

const defaultIconButtonIconColors = {
Expand Down Expand Up @@ -169,6 +170,7 @@ export default function Pog({
[styles.rounding200]: rounding === '200',
[styles.rounding300]: rounding === '300',
[styles.rounding400]: rounding === '400',
[styles.rounding500]: rounding === '500',
[styles.roundingCircle]: !rounding || rounding === 'circle',
[styles[bgColor]]: !selected,
[styles.selected]: selected,
Expand All @@ -177,12 +179,13 @@ export default function Pog({
[styles.hovered]: hovered && !focused && !active,
});

const vrClasses = classnames(styles.pog, styles[size], {
const vrClasses = classnames(styles.pog, styles[size as keyof typeof styles], {
[styles.rounding0]: rounding === '0',
[styles.rounding100]: (!rounding && size === 'xs') || rounding === '100',
[styles.rounding200]: (!rounding && size === 'sm') || rounding === '200',
[styles.rounding300]: (!rounding && size === 'md') || rounding === '300',
[styles.rounding400]: (!rounding && (size === 'lg' || size === 'xl')) || rounding === '400',
[styles.rounding400]: (!rounding && size === 'lg') || rounding === '400',
[styles.rounding500]: (!rounding && size === 'xl') || rounding === '500',
[styles.roundingCircle]: rounding === 'circle',
[styles[bgColor]]: !selected,
[styles.disabled]: disabled && !selected,
Expand All @@ -198,13 +201,33 @@ export default function Pog({
[styles.darkInnerFocus]:
focused && (bgColor === 'washLight' || focusColor === 'darkBackground'),
[styles.hovered]: hovered && !active,
// Opacity of 40% should only apply to disabled unselected states, when the icon is white or light
[styles.semitransparent]:
(bgColor === 'transparentDarkGray' ||
bgColor === 'transparent' ||
bgColor === 'transparentDarkBackground' ||
bgColor === 'washLight') &&
(color === 'white' || color === 'light') &&
disabled &&
!selected,
});

return (
<div className={isInVRExperiment ? vrClasses : classes} style={inlineStyle}>
<Icon
accessibilityLabel={accessibilityLabel || ''}
color={OLD_TO_NEW_COLOR_MAP[color]}
color={
isInVRExperiment &&
// Disabled icons should always use the disabled token, except for washLight and transparentDarkGray with white or light icons when unselected
disabled &&
!(
!selected &&
(bgColor === 'washLight' || bgColor === 'transparentDarkGray') &&
(color === 'white' || color === 'light')
)
? 'disabled'
: OLD_TO_NEW_COLOR_MAP[color]
}
dangerouslySetSvgPath={dangerouslySetSvgPath}
icon={icon}
size={iconSizeInPx}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,8 @@ exports[`ColorSchemeProvider renders styling for light mode when no color scheme
--color-background-iconbutton-semitransparentdark-default: rgba(51, 51, 51, 0.8);
--color-background-iconbutton-semitransparentdark-hover: #121212;
--color-background-iconbutton-semitransparentdark-active: #1f1f1f;
--color-background-iconbutton-semitransparentdark-disabled: #e9e9e9;
--color-background-iconbutton-semitransparentdark-disabled-default: #e9e9e9;
--color-background-iconbutton-semitransparentdark-disabled-selected: #e9e9e9;
--color-background-mask-wash: rgba(0, 0, 0, 0.04);
--color-background-overlay: #ffffff;
--color-background-popover-primary: #ffffff;
Expand Down Expand Up @@ -1294,7 +1295,8 @@ exports[`ColorSchemeProvider renders styling for light mode when specified 1`] =
--color-background-iconbutton-semitransparentdark-default: rgba(51, 51, 51, 0.8);
--color-background-iconbutton-semitransparentdark-hover: #121212;
--color-background-iconbutton-semitransparentdark-active: #1f1f1f;
--color-background-iconbutton-semitransparentdark-disabled: #e9e9e9;
--color-background-iconbutton-semitransparentdark-disabled-default: #e9e9e9;
--color-background-iconbutton-semitransparentdark-disabled-selected: #e9e9e9;
--color-background-mask-wash: rgba(0, 0, 0, 0.04);
--color-background-overlay: #ffffff;
--color-background-popover-primary: #ffffff;
Expand Down Expand Up @@ -1811,7 +1813,8 @@ exports[`ColorSchemeProvider renders styling with a custom class if has an id 1`
--color-background-iconbutton-semitransparentdark-default: rgba(51, 51, 51, 0.8);
--color-background-iconbutton-semitransparentdark-hover: #121212;
--color-background-iconbutton-semitransparentdark-active: #1f1f1f;
--color-background-iconbutton-semitransparentdark-disabled: #e9e9e9;
--color-background-iconbutton-semitransparentdark-disabled-default: #e9e9e9;
--color-background-iconbutton-semitransparentdark-disabled-selected: #e9e9e9;
--color-background-mask-wash: rgba(0, 0, 0, 0.04);
--color-background-overlay: #ffffff;
--color-background-popover-primary: #ffffff;
Expand Down Expand Up @@ -4367,10 +4370,11 @@ exports[`visual refresh tokens uses visual refresh light mode theme when specifi
--color-background-datepicker-button-selected-default: #000000;
--color-background-datepicker-button-selected-hover: #242423;
--color-background-datepicker-button-selected-active: #393937;
--color-background-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-semitransparentdark-disabled: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-iconbutton-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-iconbutton-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-iconbutton-semitransparentdark-disabled-default: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-disabled-selected: #e8e7e1;
--color-background-switch-default-unselected: #ffffff;
--color-background-switch-default-selected: #000000;
--color-background-switch-disabled-unselected: #ffffff;
Expand Down Expand Up @@ -5361,10 +5365,11 @@ exports[`visual refresh tokens uses visual refresh with ck line height 1`] = `
--color-background-datepicker-button-selected-default: #000000;
--color-background-datepicker-button-selected-hover: #242423;
--color-background-datepicker-button-selected-active: #393937;
--color-background-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-semitransparentdark-disabled: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-iconbutton-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-iconbutton-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-iconbutton-semitransparentdark-disabled-default: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-disabled-selected: #e8e7e1;
--color-background-switch-default-unselected: #ffffff;
--color-background-switch-default-selected: #000000;
--color-background-switch-disabled-unselected: #ffffff;
Expand Down Expand Up @@ -6355,10 +6360,11 @@ exports[`visual refresh tokens uses visual refresh with ja line height 1`] = `
--color-background-datepicker-button-selected-default: #000000;
--color-background-datepicker-button-selected-hover: #242423;
--color-background-datepicker-button-selected-active: #393937;
--color-background-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-semitransparentdark-disabled: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-iconbutton-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-iconbutton-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-iconbutton-semitransparentdark-disabled-default: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-disabled-selected: #e8e7e1;
--color-background-switch-default-unselected: #ffffff;
--color-background-switch-default-selected: #000000;
--color-background-switch-disabled-unselected: #ffffff;
Expand Down Expand Up @@ -7349,10 +7355,11 @@ exports[`visual refresh tokens uses visual refresh with tall line height 1`] = `
--color-background-datepicker-button-selected-default: #000000;
--color-background-datepicker-button-selected-hover: #242423;
--color-background-datepicker-button-selected-active: #393937;
--color-background-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-semitransparentdark-disabled: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-iconbutton-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-iconbutton-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-iconbutton-semitransparentdark-disabled-default: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-disabled-selected: #e8e7e1;
--color-background-switch-default-unselected: #ffffff;
--color-background-switch-default-selected: #000000;
--color-background-switch-disabled-unselected: #ffffff;
Expand Down Expand Up @@ -8343,10 +8350,11 @@ exports[`visual refresh tokens uses visual refresh with th line height 1`] = `
--color-background-datepicker-button-selected-default: #000000;
--color-background-datepicker-button-selected-hover: #242423;
--color-background-datepicker-button-selected-active: #393937;
--color-background-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-semitransparentdark-disabled: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-iconbutton-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-iconbutton-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-iconbutton-semitransparentdark-disabled-default: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-disabled-selected: #e8e7e1;
--color-background-switch-default-unselected: #ffffff;
--color-background-switch-default-selected: #000000;
--color-background-switch-disabled-unselected: #ffffff;
Expand Down Expand Up @@ -9337,10 +9345,11 @@ exports[`visual refresh tokens uses visual refresh with vi line height 1`] = `
--color-background-datepicker-button-selected-default: #000000;
--color-background-datepicker-button-selected-hover: #242423;
--color-background-datepicker-button-selected-active: #393937;
--color-background-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-semitransparentdark-disabled: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-default: rgba(0, 0, 0, 0.8);
--color-background-iconbutton-semitransparentdark-hover: rgba(36, 36, 35, 0.85);
--color-background-iconbutton-semitransparentdark-active: rgba(57, 57, 55, 0.9);
--color-background-iconbutton-semitransparentdark-disabled-default: rgba(0, 0, 0, 0.39);
--color-background-iconbutton-semitransparentdark-disabled-selected: #e8e7e1;
--color-background-switch-default-unselected: #ffffff;
--color-background-switch-default-selected: #000000;
--color-background-switch-disabled-unselected: #ffffff;
Expand Down
Loading