diff --git a/packages/@react-spectrum/s2/src/ActionButton.tsx b/packages/@react-spectrum/s2/src/ActionButton.tsx index f745883a11c..245b620b552 100644 --- a/packages/@react-spectrum/s2/src/ActionButton.tsx +++ b/packages/@react-spectrum/s2/src/ActionButton.tsx @@ -12,13 +12,14 @@ import {ActionButtonGroupContext} from './ActionButtonGroup'; import {AvatarContext} from './Avatar'; -import {baseColor, focusRing, fontRelative, lightDark, style} from '../style' with { type: 'macro' }; +import {baseColor, focusRing, fontRelative, iconStyle, lightDark, style} from '../style' with { type: 'macro' }; import {ButtonProps, ButtonRenderProps, ContextValue, OverlayTriggerStateContext, Provider, Button as RACButton, useSlottedContext} from 'react-aria-components'; import {centerBaseline} from './CenterBaseline'; import {control, getAllowedOverrides, staticColor, StyleProps} from './style-utils' with { type: 'macro' }; import {createContext, forwardRef, ReactNode, useContext} from 'react'; import {FocusableRef, FocusableRefValue} from '@react-types/shared'; import {IconContext} from './Icon'; +import {mergeStyles} from '../style/runtime'; import {NotificationBadgeContext} from './NotificationBadge'; import {pressScale} from './pressScale'; import {SkeletonContext} from './Skeleton'; @@ -144,10 +145,6 @@ export const btnStyles = style({ } } } - }, - '--iconPrimary': { - type: 'fill', - value: 'currentColor' } }, getAllowedOverrides()); @@ -194,7 +191,7 @@ export const Badge = forwardRef(function Badge(props: BadgeProps, ref: DOMRef diff --git a/packages/@react-spectrum/s2/src/Button.tsx b/packages/@react-spectrum/s2/src/Button.tsx index fd4d42728e6..434423c28c5 100644 --- a/packages/@react-spectrum/s2/src/Button.tsx +++ b/packages/@react-spectrum/s2/src/Button.tsx @@ -10,7 +10,7 @@ * governing permissions and limitations under the License. */ -import {baseColor, focusRing, fontRelative, lightDark, linearGradient, style} from '../style' with {type: 'macro'}; +import {baseColor, focusRing, fontRelative, iconStyle, lightDark, linearGradient, style} from '../style' with {type: 'macro'}; import {ButtonRenderProps, ContextValue, Link, LinkProps, OverlayTriggerStateContext, Provider, Button as RACButton, ButtonProps as RACButtonProps} from 'react-aria-components'; import {centerBaseline} from './CenterBaseline'; import {control, getAllowedOverrides, staticColor, StyleProps} from './style-utils' with {type: 'macro'}; @@ -19,6 +19,7 @@ import {FocusableRef, FocusableRefValue} from '@react-types/shared'; import {IconContext} from './Icon'; // @ts-ignore import intlMessages from '../intl/*.json'; +import {mergeStyles} from '../style/runtime'; import {pressScale} from './pressScale'; import {ProgressCircle} from './ProgressCircle'; import {SkeletonContext} from './Skeleton'; @@ -243,10 +244,6 @@ const button = style {typeof props.children === 'string' ? {props.children} : props.children} @@ -458,7 +457,10 @@ export const LinkButton = forwardRef(function LinkButton(props: LinkButtonProps, }], [IconContext, { render: centerBaseline({slot: 'icon', styles: style({order: 0})}), - styles: style({size: fontRelative(20), marginStart: '--iconMargin', flexShrink: 0}) + styles: mergeStyles( + iconStyle({color: 'currentColor'}), + style({size: fontRelative(20), marginStart: '--iconMargin', flexShrink: 0}) + ) }] ]}> {typeof props.children === 'string' ? {props.children} : props.children} diff --git a/packages/@react-spectrum/s2/src/ComboBox.tsx b/packages/@react-spectrum/s2/src/ComboBox.tsx index 5e0fbc124f5..32256d0f1cb 100644 --- a/packages/@react-spectrum/s2/src/ComboBox.tsx +++ b/packages/@react-spectrum/s2/src/ComboBox.tsx @@ -33,7 +33,7 @@ import { Virtualizer } from 'react-aria-components'; import {AsyncLoadable, HelpTextProps, LoadingState, SpectrumLabelableProps} from '@react-types/shared'; -import {baseColor, edgeToText, focusRing, space, style} from '../style' with {type: 'macro'}; +import {baseColor, edgeToText, focusRing, iconStyle, space, style} from '../style' with {type: 'macro'}; import {centerBaseline} from './CenterBaseline'; import {centerPadding, control, controlBorderRadius, controlFont, controlSize, field, fieldInput, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'}; import { @@ -57,6 +57,7 @@ import {IconContext} from './Icon'; // @ts-ignore import intlMessages from '../intl/*.json'; import {mergeRefs, useResizeObserver, useSlotId} from '@react-aria/utils'; +import {mergeStyles} from '../style/runtime'; import {Node} from 'react-stately'; import {Placement} from 'react-aria'; import {PopoverBase} from './Popover'; @@ -389,7 +390,7 @@ export function ComboBoxItem(props: ComboBoxItemProps): ReactNode { values={[ [IconContext, { slots: { - icon: {render: centerBaseline({slot: 'icon', styles: iconCenterWrapper}), styles: icon} + icon: {render: centerBaseline({slot: 'icon', styles: iconCenterWrapper}), styles: mergeStyles(iconStyle({color: 'currentColor'}), icon)} } }], [TextContext, { diff --git a/packages/@react-spectrum/s2/src/Menu.tsx b/packages/@react-spectrum/s2/src/Menu.tsx index aa990d5744b..7ae1d136af1 100644 --- a/packages/@react-spectrum/s2/src/Menu.tsx +++ b/packages/@react-spectrum/s2/src/Menu.tsx @@ -28,7 +28,7 @@ import { Separator, SeparatorProps } from 'react-aria-components'; -import {baseColor, edgeToText, focusRing, fontRelative, size, space, style} from '../style' with {type: 'macro'}; +import {baseColor, edgeToText, focusRing, fontRelative, iconStyle, size, space, style} from '../style' with {type: 'macro'}; import {box, iconStyles} from './Checkbox'; import {centerBaseline} from './CenterBaseline'; import {centerPadding, control, controlFont, controlSize, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'}; @@ -221,11 +221,7 @@ export let icon = style({ size: fontRelative(20), // too small default icon size is wrong, it's like the icons are 1 tshirt size bigger than the rest of the component? check again after typography changes // reminder, size of WF is applied via font size - marginEnd: 'text-to-visual', - '--iconPrimary': { - type: 'fill', - value: 'currentColor' - } + marginEnd: 'text-to-visual' }); export let iconCenterWrapper = style({ @@ -305,11 +301,7 @@ let keyboard = style<{size: 'S' | 'M' | 'L' | 'XL', isDisabled: boolean}>({ let descriptor = style({ gridArea: 'descriptor', - marginStart: 8, - '--iconPrimary': { - type: 'fill', - value: 'currentColor' - } + marginStart: 8 }); let InternalMenuContext = createContext<{size: 'S' | 'M' | 'L' | 'XL', isSubmenu: boolean, hideLinkOutIcon: boolean}>({ @@ -486,8 +478,8 @@ export function MenuItem(props: MenuItemProps): ReactNode { values={[ [IconContext, { slots: { - icon: {render: centerBaseline({slot: 'icon', styles: iconCenterWrapper}), styles: icon}, - descriptor: {render: centerBaseline({slot: 'descriptor', styles: descriptor})} // TODO: remove once we have default? + icon: {render: centerBaseline({slot: 'icon', styles: iconCenterWrapper}), styles: mergeStyles(iconStyle({color: 'currentColor'}), icon)}, + descriptor: {render: centerBaseline({slot: 'descriptor', styles: descriptor}), styles: iconStyle({color: 'currentColor'})} // TODO: remove once we have default? } }], [TextContext, { @@ -517,6 +509,10 @@ export function MenuItem(props: MenuItemProps): ReactNode { direction: { rtl: -1 } + }, + '--iconPrimary': { + type: 'fill', + value: 'currentColor' } })({direction})} /> @@ -530,6 +526,10 @@ export function MenuItem(props: MenuItemProps): ReactNode { direction: { rtl: -1 } + }, + '--iconPrimary': { + type: 'fill', + value: 'currentColor' } })({direction})} /> diff --git a/packages/@react-spectrum/s2/src/Picker.tsx b/packages/@react-spectrum/s2/src/Picker.tsx index 5928c3795ce..90029dc9d4b 100644 --- a/packages/@react-spectrum/s2/src/Picker.tsx +++ b/packages/@react-spectrum/s2/src/Picker.tsx @@ -32,7 +32,7 @@ import { Virtualizer } from 'react-aria-components'; import {AsyncLoadable, FocusableRef, FocusableRefValue, HelpTextProps, LoadingState, PressEvent, RefObject, SpectrumLabelableProps} from '@react-types/shared'; -import {baseColor, edgeToText, focusRing, style} from '../style' with {type: 'macro'}; +import {baseColor, edgeToText, focusRing, iconStyle, style} from '../style' with {type: 'macro'}; import {centerBaseline} from './CenterBaseline'; import { checkmark, @@ -64,6 +64,7 @@ import {HeaderContext, HeadingContext, Text, TextContext} from './Content'; import {IconContext} from './Icon'; // @ts-ignore import intlMessages from '../intl/*.json'; +import {mergeStyles} from '../style/runtime'; import {Placement} from 'react-aria'; import {PopoverBase} from './Popover'; import {PressResponder} from '@react-aria/interactions'; @@ -515,7 +516,7 @@ const PickerButton = createHideableComponent(function PickerButton ({ userSelect: 'none', backgroundColor: 'transparent', borderStyle: 'none', - '--iconPrimary': { - type: 'fill', - value: 'currentColor' - }, // The selected item has lower z-index so that the sliding background // animation does not cover other items. zIndex: { @@ -264,7 +260,8 @@ export const SegmentedControlItem = /*#__PURE__*/ forwardRef(function SegmentedC {typeof props.children === 'string' ? {props.children} : props.children} diff --git a/packages/@react-spectrum/s2/src/TabsPicker.tsx b/packages/@react-spectrum/s2/src/TabsPicker.tsx index a480bcfbca8..7a2dd7f1ff2 100644 --- a/packages/@react-spectrum/s2/src/TabsPicker.tsx +++ b/packages/@react-spectrum/s2/src/TabsPicker.tsx @@ -23,7 +23,7 @@ import { Provider, SelectValue } from 'react-aria-components'; -import {baseColor, edgeToText, focusRing, size, style} from '../style' with {type: 'macro'}; +import {baseColor, edgeToText, focusRing, iconStyle, size, style} from '../style' with {type: 'macro'}; import {centerBaseline} from './CenterBaseline'; import { checkmark, @@ -44,6 +44,7 @@ import {FocusableRef, FocusableRefValue, SpectrumLabelableProps} from '@react-ty import {forwardRefType} from './types'; import {HeaderContext, HeadingContext, Text, TextContext} from './Content'; import {IconContext} from './Icon'; +import {mergeStyles} from '../style/runtime'; import {Placement} from 'react-aria'; import {PopoverBase} from './Popover'; import {pressScale} from './pressScale'; @@ -207,7 +208,7 @@ function Picker(props: PickerProps, ref: FocusableRef {typeof props.children === 'string' ? {props.children} : props.children} diff --git a/packages/@react-spectrum/s2/src/TreeView.tsx b/packages/@react-spectrum/s2/src/TreeView.tsx index 9c6062710a9..40db8a3c5c3 100644 --- a/packages/@react-spectrum/s2/src/TreeView.tsx +++ b/packages/@react-spectrum/s2/src/TreeView.tsx @@ -29,10 +29,11 @@ import { import {centerBaseline} from './CenterBaseline'; import {Checkbox} from './Checkbox'; import Chevron from '../ui-icons/Chevron'; -import {colorMix, focusRing, fontRelative, lightDark, style} from '../style' with {type: 'macro'}; +import {colorMix, focusRing, fontRelative, iconStyle, lightDark, style} from '../style' with {type: 'macro'}; import {DOMRef, Key} from '@react-types/shared'; import {getAllowedOverrides, StylesPropWithHeight, UnsafeStyles} from './style-utils' with {type: 'macro'}; import {IconContext} from './Icon'; +import {mergeStyles} from '../style/runtime'; import {raw} from '../style/style-macro' with {type: 'macro'}; import React, {createContext, forwardRef, JSXElementConstructor, ReactElement, ReactNode, useContext, useRef} from 'react'; import {TextContext} from './Content'; @@ -242,11 +243,7 @@ const treeCheckbox = style({ const treeIcon = style({ gridArea: 'icon', - marginEnd: 'text-to-visual', - '--iconPrimary': { - type: 'fill', - value: 'currentColor' - } + marginEnd: 'text-to-visual' }); const treeContent = style({ @@ -353,7 +350,7 @@ export const TreeViewItemContent = (props: TreeViewItemContentProps): ReactNode [TextContext, {styles: treeContent}], [IconContext, { render: centerBaseline({slot: 'icon', styles: treeIcon}), - styles: style({size: fontRelative(20), flexShrink: 0}) + styles: mergeStyles(iconStyle({color: 'currentColor'}), style({size: fontRelative(20), flexShrink: 0})) }], [ActionButtonGroupContext, {styles: treeActions}], [ActionMenuContext, {styles: treeActionMenu, isQuiet: true}] diff --git a/packages/@react-spectrum/s2/style/index.ts b/packages/@react-spectrum/s2/style/index.ts index fb2c934e69a..f2be7db5428 100644 --- a/packages/@react-spectrum/s2/style/index.ts +++ b/packages/@react-spectrum/s2/style/index.ts @@ -43,7 +43,7 @@ export const focusRing = () => ({ interface IconStyle { size?: 'XS' | 'S' | 'M' | 'L' |'XL', - color?: 'white' | 'black' | 'accent' | 'neutral' | 'negative' | 'informative' | 'positive' | 'notice' | 'gray' | 'red' | 'orange' | 'yellow' | 'chartreuse' | 'celery' | 'green' | 'seafoam' | 'cyan' | 'blue' | 'indigo' | 'purple' | 'fuchsia' | 'magenta' | 'pink' | 'turquoise' | 'cinnamon' | 'brown' | 'silver', + color?: 'white' | 'black' | 'accent' | 'neutral' | 'negative' | 'informative' | 'positive' | 'notice' | 'gray' | 'red' | 'orange' | 'yellow' | 'chartreuse' | 'celery' | 'green' | 'seafoam' | 'cyan' | 'blue' | 'indigo' | 'purple' | 'fuchsia' | 'magenta' | 'pink' | 'turquoise' | 'cinnamon' | 'brown' | 'silver' | 'currentColor', margin?: Spacing, marginStart?: Spacing, marginEnd?: Spacing, @@ -81,7 +81,7 @@ const iconSizes = { export function iconStyle(this: MacroContext | void, options: IconStyle): StyleString> { let {size = 'M', color, ...styles} = options; - + if (color) { styles['--iconPrimary'] = { type: 'fill',