An open source design system that's fully customizable and agent ready
TypeScript
remove useHoverState (#63)
Cindy Zhangb50843363b71
diff --git a/apps/storybook/stories/CheckboxInput.stories.tsx b/apps/storybook/stories/CheckboxInput.stories.tsxindex c9e13b7c0d..6a517d124d 100644--- a/apps/storybook/stories/CheckboxInput.stories.tsx+++ b/apps/storybook/stories/CheckboxInput.stories.tsx@@ -53,9 +53,16 @@ type Story = StoryObj<typeof XDSCheckboxInput>;export const Default: Story = {render: args => {const [value, setValue] = useState<boolean | 'indeterminate'>(- args.value ?? false+ args.value ?? false,+ );+ const {value: _, onChange: __, ...restArgs} = args;+ return (+ <XDSCheckboxInput+ {...restArgs}+ value={value}+ onChange={checked => setValue(checked)}+ />);- return <XDSCheckboxInput {...args} value={value} onChange={setValue} />;},args: {label: 'Accept terms and conditions',@@ -65,9 +72,16 @@ export const Default: Story = {export const Checked: Story = {render: args => {const [value, setValue] = useState<boolean | 'indeterminate'>(- args.value ?? true+ args.value ?? true,+ );+ const {value: _, onChange: __, ...restArgs} = args;+ return (+ <XDSCheckboxInput+ {...restArgs}+ value={value}+ onChange={checked => setValue(checked)}+ />);- return <XDSCheckboxInput {...args} value={value} onChange={setValue} />;},args: {label: 'I agree to the terms',@@ -78,9 +92,16 @@ export const Checked: Story = {export const WithDescription: Story = {render: args => {const [value, setValue] = useState<boolean | 'indeterminate'>(- args.value ?? false+ args.value ?? false,+ );+ const {value: _, onChange: __, ...restArgs} = args;+ return (+ <XDSCheckboxInput+ {...restArgs}+ value={value}+ onChange={checked => setValue(checked)}+ />);- return <XDSCheckboxInput {...args} value={value} onChange={setValue} />;},args: {label: 'Subscribe to newsletter',@@ -91,9 +112,16 @@ export const WithDescription: Story = {export const WithHiddenLabel: Story = {render: args => {const [value, setValue] = useState<boolean | 'indeterminate'>(- args.value ?? false+ args.value ?? false,+ );+ const {value: _, onChange: __, ...restArgs} = args;+ return (+ <XDSCheckboxInput+ {...restArgs}+ value={value}+ onChange={checked => setValue(checked)}+ />);- return <XDSCheckboxInput {...args} value={value} onChange={setValue} />;},args: {label: 'Select row',@@ -104,9 +132,16 @@ export const WithHiddenLabel: Story = {export const Indeterminate: Story = {render: args => {const [value, setValue] = useState<boolean | 'indeterminate'>(- args.value ?? 'indeterminate'+ args.value ?? 'indeterminate',+ );+ const {value: _, onChange: __, ...restArgs} = args;+ return (+ <XDSCheckboxInput+ {...restArgs}+ value={value}+ onChange={checked => setValue(checked)}+ />);- return <XDSCheckboxInput {...args} value={value} onChange={setValue} />;},args: {label: 'Select all items',@@ -118,9 +153,16 @@ export const Indeterminate: Story = {export const Disabled: Story = {render: args => {const [value, setValue] = useState<boolean | 'indeterminate'>(- args.value ?? false+ args.value ?? false,+ );+ const {value: _, onChange: __, ...restArgs} = args;+ return (+ <XDSCheckboxInput+ {...restArgs}+ value={value}+ onChange={checked => setValue(checked)}+ />);- return <XDSCheckboxInput {...args} value={value} onChange={setValue} />;},args: {label: 'Premium feature',@@ -132,9 +174,16 @@ export const Disabled: Story = {export const DisabledChecked: Story = {render: args => {const [value, setValue] = useState<boolean | 'indeterminate'>(- args.value ?? true+ args.value ?? true,+ );+ const {value: _, onChange: __, ...restArgs} = args;+ return (+ <XDSCheckboxInput+ {...restArgs}+ value={value}+ onChange={checked => setValue(checked)}+ />);- return <XDSCheckboxInput {...args} value={value} onChange={setValue} />;},args: {label: 'Feature enabled',@@ -148,7 +197,7 @@ export const AllVariations: Story = {const [value1, setValue1] = useState<boolean | 'indeterminate'>(false);const [value2, setValue2] = useState<boolean | 'indeterminate'>(true);const [value3, setValue3] = useState<boolean | 'indeterminate'>(- 'indeterminate'+ 'indeterminate',);const [value4, setValue4] = useState<boolean | 'indeterminate'>(false);const [value5, setValue5] = useState<boolean | 'indeterminate'>(true);@@ -192,9 +241,16 @@ export const AllVariations: Story = {export const SmallSize: Story = {render: args => {const [value, setValue] = useState<boolean | 'indeterminate'>(- args.value ?? false+ args.value ?? false,+ );+ const {value: _, onChange: __, ...restArgs} = args;+ return (+ <XDSCheckboxInput+ {...restArgs}+ value={value}+ onChange={checked => setValue(checked)}+ />);- return <XDSCheckboxInput {...args} value={value} onChange={setValue} />;},args: {label: 'Compact checkbox',@@ -248,9 +304,16 @@ export const SizeComparison: Story = {export const WithStartIcon: Story = {render: args => {const [value, setValue] = useState<boolean | 'indeterminate'>(- args.value ?? false+ args.value ?? false,+ );+ const {value: _, onChange: __, ...restArgs} = args;+ return (+ <XDSCheckboxInput+ {...restArgs}+ value={value}+ onChange={checked => setValue(checked)}+ />);- return <XDSCheckboxInput {...args} value={value} onChange={setValue} />;},args: {label: 'Enable notifications',diff --git a/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx b/packages/core/src/CheckboxInput/XDSCheckboxInput.tsxindex 6e5814bcf7..8a32a06586 100644--- a/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx+++ b/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx@@ -1,6 +1,6 @@/*** @file XDSCheckboxInput.tsx- * @input Uses React forwardRef, useId, ChangeEvent, XDSFieldLabel, useHoverState, XDSIconType+ * @input Uses React forwardRef, useId, ChangeEvent, XDSFieldLabel, XDSIconType* @output Exports XDSCheckboxInput component, XDSCheckboxInputProps* @position Core implementation; consumed by index.ts, tested by XDSCheckboxInput.test.tsx*@@ -21,7 +21,6 @@ import {typographyVars,} from '../theme/tokens.stylex';import {XDSFieldLabel} from '../Field/XDSFieldLabel';-import {useHoverState} from '../hooks/useHoverState';import type {XDSIconType} from '../Icon';const styles = stylex.create({@@ -30,6 +29,30 @@ const styles = stylex.create({alignItems: 'flex-start',gap: spacingVars['--spacing-2'],},+ // Default CSS variables for unchecked state+ containerUnchecked: {+ '--xds-checkbox-bg': colorVars['--color-surface'],+ '--xds-checkbox-border': colorVars['--color-divider-emphasized'],+ },+ // Default CSS variables for checked/indeterminate state+ containerChecked: {+ '--xds-checkbox-bg': colorVars['--color-accent'],+ '--xds-checkbox-border': colorVars['--color-accent'],+ },+ // Hover overrides for unchecked (only applied when not disabled)+ containerHoverUnchecked: {+ ':hover': {+ '--xds-checkbox-bg': `color-mix(in srgb, ${colorVars['--color-surface']}, ${colorVars['--color-hover-tint']} 5%)`,+ '--xds-checkbox-border': `color-mix(in srgb, ${colorVars['--color-divider-emphasized']}, ${colorVars['--color-hover-tint']} 20%)`,+ },+ },+ // Hover overrides for checked/indeterminate (only applied when not disabled)+ containerHoverChecked: {+ ':hover': {+ '--xds-checkbox-bg': `color-mix(in srgb, ${colorVars['--color-accent']}, ${colorVars['--color-hover-tint']} 15%)`,+ '--xds-checkbox-border': `color-mix(in srgb, ${colorVars['--color-accent']}, ${colorVars['--color-hover-tint']} 15%)`,+ },+ },checkboxWrapper: {position: 'relative',display: 'flex',@@ -43,6 +66,7 @@ const styles = stylex.create({padding: 0,opacity: 0,cursor: 'pointer',+ zIndex: 1,},inputDisabled: {cursor: 'not-allowed',@@ -53,24 +77,12 @@ const styles = stylex.create({justifyContent: 'center',borderWidth: 1,borderStyle: 'solid',- borderColor: colorVars['--color-divider-emphasized'],+ borderColor: 'var(--xds-checkbox-border)',borderRadius: radiusVars['--radius-content'],- backgroundColor: colorVars['--color-surface'],+ backgroundColor: 'var(--xds-checkbox-bg)',transitionProperty: 'background-color, border-color',transitionDuration: transitionVars['--transition-fast'],},- checkboxHover: {- backgroundColor: colorVars['--color-deemphasized'],- borderColor: colorVars['--color-divider-high-contrast'],- },- checkboxCheckedHover: {- backgroundColor: '#0050B8',- borderColor: '#0050B8',- },- checkboxChecked: {- backgroundColor: colorVars['--color-accent'],- borderColor: colorVars['--color-accent'],- },checkboxFocused: {outline: `2px solid ${colorVars['--color-focus-outline']}`,outlineOffset: 2,@@ -84,7 +96,7 @@ const styles = stylex.create({},checkmark: {display: 'none',- fill: colorVars['--color-icon-on-media'],+ color: colorVars['--color-icon-on-media'],},checkmarkVisible: {display: 'block',@@ -253,21 +265,27 @@ export const XDSCheckboxInput = forwardRef<onBlur,startIcon,},- ref+ ref,) => {const id = useId();const descriptionID = useId();- const {isHovered, onMouseEnter, onMouseLeave} = useHoverState();const isIndeterminate = value === 'indeterminate';const isChecked = value === true;- const showHover = isHovered && !isDisabled;+ const isCheckedOrIndeterminate = isChecked || isIndeterminate;return (<div- {...stylex.props(styles.container)}- onMouseEnter={onMouseEnter}- onMouseLeave={onMouseLeave}>+ {...stylex.props(+ styles.container,+ isCheckedOrIndeterminate+ ? styles.containerChecked+ : styles.containerUnchecked,+ !isDisabled &&+ (isCheckedOrIndeterminate+ ? styles.containerHoverChecked+ : styles.containerHoverUnchecked),+ )}><div {...stylex.props(styles.checkboxWrapper, wrapperSizeStyles[size])}><inputref={ref}@@ -283,7 +301,7 @@ export const XDSCheckboxInput = forwardRef<{...stylex.props(styles.input,wrapperSizeStyles[size],- isDisabled && styles.inputDisabled+ isDisabled && styles.inputDisabled,)}/><div@@ -291,30 +309,21 @@ export const XDSCheckboxInput = forwardRef<{...stylex.props(styles.checkbox,checkboxSizeStyles[size],- (isChecked || isIndeterminate) && styles.checkboxChecked,- showHover &&- !isChecked &&- !isIndeterminate &&- styles.checkboxHover,- showHover &&- (isChecked || isIndeterminate) &&- styles.checkboxCheckedHover,isDisabled && styles.checkboxDisabled,isDisabled &&- !isChecked &&- !isIndeterminate &&- styles.checkboxDisabledUnchecked+ !isCheckedOrIndeterminate &&+ styles.checkboxDisabledUnchecked,)}><svgviewBox="0 0 10 10"{...stylex.props(styles.checkmark,checkmarkSizeStyles[size],- isChecked && styles.checkmarkVisible+ isChecked && styles.checkmarkVisible,)}><pathd="M8.5 2.5L4 7.5L1.5 5"- stroke="white"+ stroke="currentColor"strokeWidth="1.5"fill="none"strokeLinecap="round"@@ -325,7 +334,7 @@ export const XDSCheckboxInput = forwardRef<{...stylex.props(styles.indeterminateMark,indeterminateSizeStyles[size],- isIndeterminate && styles.indeterminateMarkVisible+ isIndeterminate && styles.indeterminateMarkVisible,)}/></div>@@ -347,7 +356,7 @@ export const XDSCheckboxInput = forwardRef<</div></div>);- }+ },);XDSCheckboxInput.displayName = 'XDSCheckboxInput';diff --git a/packages/core/src/hooks/index.ts b/packages/core/src/hooks/index.tsindex 5e186c4bc7..6eaf9bbe3e 100644--- a/packages/core/src/hooks/index.ts+++ b/packages/core/src/hooks/index.ts@@ -7,5 +7,5 @@* SYNC: When modified, update this header*/-export {useHoverState} from './useHoverState';-export type {UseHoverStateResult} from './useHoverState';+// Hooks will be added here as needed+export {};diff --git a/packages/core/src/hooks/useHoverState.ts b/packages/core/src/hooks/useHoverState.tsdeleted file mode 100644index 7d793c8516..0000000000--- a/packages/core/src/hooks/useHoverState.ts+++ /dev/null@@ -1,51 +0,0 @@-/**- * @file useHoverState.ts- * @input Uses React useState, useCallback- * @output Exports useHoverState hook- * @position Utility hook for tracking hover state on elements- *- * SYNC: When modified, update this header- */--import {useState, useCallback} from 'react';--export interface UseHoverStateResult {- isHovered: boolean;- onMouseEnter: () => void;- onMouseLeave: () => void;-}--/**- * A hook for tracking hover state on an element.- *- * @example- * ```tsx- * const {isHovered, onMouseEnter, onMouseLeave} = useHoverState();- * return (- * <div- * onMouseEnter={onMouseEnter}- * onMouseLeave={onMouseLeave}- * style={{backgroundColor: isHovered ? 'blue' : 'transparent'}}- * >- * Hover me- * </div>- * );- * ```- */-export function useHoverState(): UseHoverStateResult {- const [isHovered, setIsHovered] = useState(false);-- const onMouseEnter = useCallback(() => {- setIsHovered(true);- }, []);-- const onMouseLeave = useCallback(() => {- setIsHovered(false);- }, []);-- return {- isHovered,- onMouseEnter,- onMouseLeave,- };-}diff --git a/packages/core/src/theme/defaultTheme.stylex.ts b/packages/core/src/theme/defaultTheme.stylex.tsindex 46868f28c1..81cb1f2161 100644--- a/packages/core/src/theme/defaultTheme.stylex.ts+++ b/packages/core/src/theme/defaultTheme.stylex.ts@@ -105,6 +105,8 @@ const colorRaw = {'--color-glimmer-high-contrast': 'light-dark(#A4B0BC, #8C939B)','--color-shadow-elevation':'light-dark(rgba(5, 54, 89, 0.1), rgba(0, 0, 0, 0.3))',+ // Hover tint: black in light mode, white in dark mode - used with color-mix for hover states+ '--color-hover-tint': 'light-dark(black, white)',// Literal color sets - Blue'--color-blue-background': 'light-dark(#0171E333, #0171E333)',diff --git a/packages/core/src/theme/neutralTheme.stylex.ts b/packages/core/src/theme/neutralTheme.stylex.tsindex e68bb1e18b..e5a7c09e0a 100644--- a/packages/core/src/theme/neutralTheme.stylex.ts+++ b/packages/core/src/theme/neutralTheme.stylex.ts@@ -74,14 +74,14 @@ const colorRaw = {'--color-text-disabled': 'light-dark(oklch(0.708 0 0), oklch(0.439 0 0))','--color-text-link': 'light-dark(oklch(0.205 0 0), oklch(0.922 0 0))','--color-text-placeholder': 'light-dark(oklch(0.556 0 0), oklch(0.556 0 0))',- '--color-text-on-media': 'light-dark(oklch(1 0 0), oklch(1 0 0))',+ '--color-text-on-media': 'light-dark(oklch(1 0 0), oklch(0.145 0 0))',// Icon'--color-icon-primary': 'light-dark(oklch(0.145 0 0), oklch(0.985 0 0))','--color-icon-secondary': 'light-dark(oklch(0.556 0 0), oklch(0.708 0 0))','--color-icon-tertiary': 'light-dark(oklch(0.708 0 0), oklch(0.556 0 0))','--color-icon-disabled': 'light-dark(oklch(0.708 0 0), oklch(0.439 0 0))',- '--color-icon-on-media': 'light-dark(oklch(1 0 0), oklch(1 0 0))',+ '--color-icon-on-media': 'light-dark(oklch(1 0 0), oklch(0.145 0 0))',// Surface variants'--color-card': 'light-dark(oklch(1 0 0), oklch(0.205 0 0))',@@ -119,6 +119,8 @@ const colorRaw = {'light-dark(oklch(0.85 0 0), oklch(0.439 0 0))','--color-shadow-elevation':'light-dark(oklch(0 0 0 / 10%), oklch(0 0 0 / 30%))',+ // Hover tint: black in light mode, white in dark mode - used with color-mix for hover states+ '--color-hover-tint': 'light-dark(black, white)',// Literal color sets - Blue'--color-blue-background':diff --git a/packages/core/src/theme/tokens.stylex.ts b/packages/core/src/theme/tokens.stylex.tsindex ece09da7a6..e8015dfd5c 100644--- a/packages/core/src/theme/tokens.stylex.ts+++ b/packages/core/src/theme/tokens.stylex.ts@@ -65,6 +65,8 @@ export const colorRaw = {'--color-glimmer': '#CCD3DB','--color-glimmer-high-contrast': '#A4B0BC','--color-shadow-elevation': 'rgba(5, 54, 89, 0.1)',+ // Hover tint: black in light mode, white in dark mode - used with color-mix for hover states+ '--color-hover-tint': 'black',// Blue'--color-blue-background': '#0171E333',