Skip to content

fix: Icon coloring rules #8323

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 packages/@react-spectrum/s2/src/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -144,10 +145,6 @@ export const btnStyles = style<ButtonRenderProps & ActionButtonStyleProps & Togg
}
}
},
'--iconPrimary': {
type: 'fill',
value: 'currentColor'
},
outlineColor: {
default: 'focus-ring',
isStaticColor: 'transparent-overlay-1000',
Expand Down Expand Up @@ -287,7 +284,10 @@ export const ActionButton = forwardRef(function ActionButton(props: ActionButton
[TextContext, {styles: style({order: 1, truncate: true})}],
[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})
)
}],
[AvatarContext, {
size: avatarSize[size],
Expand Down
9 changes: 3 additions & 6 deletions packages/@react-spectrum/s2/src/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import {centerBaseline} from './CenterBaseline';
import {ContextValue, Provider, TextContext as RACTextContext, SlotProps} from 'react-aria-components';
import {control, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
import {filterDOMProps} from '@react-aria/utils';
import {fontRelative, lightDark, style} from '../style' with {type: 'macro'};
import {fontRelative, iconStyle, lightDark, style} from '../style' with {type: 'macro'};
import {IconContext} from './Icon';
import {mergeStyles} from '../style/runtime';
import React, {createContext, forwardRef, ReactNode} from 'react';
import {SkeletonWrapper} from './Skeleton';
import {Text, TextContext} from './Content';
Expand Down Expand Up @@ -155,10 +156,6 @@ const badge = style<BadgeStyleProps>({
}
}
}
},
'--iconPrimary': {
type: 'fill',
value: 'currentColor'
}
}, getAllowedOverrides());

Expand Down Expand Up @@ -194,7 +191,7 @@ export const Badge = forwardRef(function Badge(props: BadgeProps, ref: DOMRef<HT
[RACTextContext, {}],
[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}))
}]
]}>
<SkeletonWrapper>
Expand Down
32 changes: 17 additions & 15 deletions packages/@react-spectrum/s2/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand All @@ -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';
Expand Down Expand Up @@ -243,10 +244,6 @@ const button = style<ButtonRenderProps & ButtonStyleProps & {isStaticColor: bool
}
}
},
'--iconPrimary': {
type: 'fill',
value: 'currentColor'
},
outlineColor: {
default: 'focus-ring',
isStaticColor: 'transparent-overlay-1000',
Expand Down Expand Up @@ -376,15 +373,17 @@ export const Button = forwardRef(function Button(props: ButtonProps, ref: Focusa
}],
[IconContext, {
render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
styles: style({
size: fontRelative(20),
marginStart: '--iconMargin',
flexShrink: 0,
opacity: {
default: 1,
isProgressVisible: 0
}
})({isProgressVisible})
styles: mergeStyles(
iconStyle({color: 'currentColor'}),
style({
size: fontRelative(20),
marginStart: '--iconMargin',
flexShrink: 0,
opacity: {
default: 1,
isProgressVisible: 0
}
})({isProgressVisible}))
}]
]}>
{typeof props.children === 'string' ? <Text>{props.children}</Text> : props.children}
Expand Down Expand Up @@ -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' ? <Text>{props.children}</Text> : props.children}
Expand Down
5 changes: 3 additions & 2 deletions packages/@react-spectrum/s2/src/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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';
Expand Down Expand Up @@ -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, {
Expand Down
26 changes: 13 additions & 13 deletions packages/@react-spectrum/s2/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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}>({
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -517,6 +509,10 @@ export function MenuItem(props: MenuItemProps): ReactNode {
direction: {
rtl: -1
}
},
'--iconPrimary': {
type: 'fill',
value: 'currentColor'
}
})({direction})} />
</div>
Expand All @@ -530,6 +526,10 @@ export function MenuItem(props: MenuItemProps): ReactNode {
direction: {
rtl: -1
}
},
'--iconPrimary': {
type: 'fill',
value: 'currentColor'
}
})({direction})} />
</div>
Expand Down
7 changes: 4 additions & 3 deletions packages/@react-spectrum/s2/src/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -515,7 +516,7 @@ const PickerButton = createHideableComponent(function PickerButton<T extends obj
slots: {
icon: {
render: centerBaseline({slot: 'icon', styles: iconCenterWrapper}),
styles: icon
styles: mergeStyles(iconStyle({color: 'currentColor'}), icon)
}
}
}],
Expand Down Expand Up @@ -581,7 +582,7 @@ export function PickerItem(props: PickerItemProps): ReactNode {
<DefaultProvider
context={IconContext}
value={{slots: {
icon: {render: centerBaseline({slot: 'icon', styles: iconCenterWrapper}), styles: icon}
icon: {render: centerBaseline({slot: 'icon', styles: iconCenterWrapper}), styles: mergeStyles(iconStyle({color: 'currentColor'}), icon)}
}}}>
<DefaultProvider
context={TextContext}
Expand Down
9 changes: 3 additions & 6 deletions packages/@react-spectrum/s2/src/SegmentedControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import {AriaLabelingProps, DOMRef, DOMRefValue, FocusableRef, Key} from '@react-types/shared';
import {baseColor, focusRing, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, iconStyle, style} from '../style' with {type: 'macro'};
import {centerBaseline} from './CenterBaseline';
import {ContextValue, DEFAULT_SLOT, Provider, TextContext as RACTextContext, SlotProps, ToggleButton, ToggleButtonGroup, ToggleButtonRenderProps, ToggleGroupStateContext} from 'react-aria-components';
import {control, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
Expand Down Expand Up @@ -90,10 +90,6 @@ const controlItem = style<ToggleButtonRenderProps & {isJustified?: boolean}>({
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: {
Expand Down Expand Up @@ -264,7 +260,8 @@ export const SegmentedControlItem = /*#__PURE__*/ forwardRef(function SegmentedC
<Provider
values={[
[IconContext, {
render: centerBaseline({slot: 'icon', styles: style({order: 0, flexShrink: 0})})
render: centerBaseline({slot: 'icon', styles: style({order: 0, flexShrink: 0})}),
styles: iconStyle({color: 'currentColor'})
}],
[RACTextContext, {slots: {[DEFAULT_SLOT]: {}}}],
[TextContext, {styles: style({order: 1, truncate: true})}]
Expand Down
11 changes: 4 additions & 7 deletions packages/@react-spectrum/s2/src/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import {
TabListStateContext,
TabRenderProps
} from 'react-aria-components';
import {baseColor, focusRing, size, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, iconStyle, size, style} from '../style' with {type: 'macro'};
import {centerBaseline} from './CenterBaseline';
import {Collection, DOMRef, DOMRefValue, Key, Node, Orientation, RefObject} from '@react-types/shared';
import {CollectionBuilder} from '@react-aria/collections';
import {createContext, forwardRef, ReactNode, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import {getAllowedOverrides, StyleProps, StylesPropWithHeight, UnsafeStyles} from './style-utils' with {type: 'macro'};
import {IconContext} from './Icon';
import {inertValue, useEffectEvent, useId, useLabels, useLayoutEffect, useResizeObserver} from '@react-aria/utils';
import {mergeStyles} from '../style/runtime';
import {Picker, PickerItem} from './TabsPicker';
import {Text, TextContext} from './Content';
import {useControlledState} from '@react-stately/utils';
Expand Down Expand Up @@ -358,11 +359,7 @@ const tab = style<TabRenderProps & {density?: 'compact' | 'regular', labelBehavi

const icon = style({
display: 'block',
flexShrink: 0,
'--iconPrimary': {
type: 'fill',
value: 'currentColor'
}
flexShrink: 0
});

export function Tab(props: TabProps): ReactNode {
Expand Down Expand Up @@ -402,7 +399,7 @@ export function Tab(props: TabProps): ReactNode {
}],
[IconContext, {
render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
styles: icon
styles: mergeStyles(iconStyle({color: 'currentColor'}), icon)
}]
]}>
{typeof props.children === 'string' ? <Text>{props.children}</Text> : props.children}
Expand Down
5 changes: 3 additions & 2 deletions packages/@react-spectrum/s2/src/TabsPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -207,7 +208,7 @@ function Picker<T extends object>(props: PickerProps<T>, ref: FocusableRef<HTMLB
slots: {
icon: {
render: centerBaseline({slot: 'icon', styles: iconCenterWrapper({labelBehavior})}),
styles: icon
styles: mergeStyles(iconStyle({color: 'currentColor'}), icon)
}
}
}],
Expand Down
9 changes: 3 additions & 6 deletions packages/@react-spectrum/s2/src/TagGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
useSlottedContext
} from 'react-aria-components';
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 {CenterBaseline, centerBaseline} from './CenterBaseline';
import {ClearButton} from './ClearButton';
import {Collection, CollectionBuilder} from '@react-aria/collections';
Expand All @@ -44,6 +44,7 @@ import {ImageContext} from './Image';
import {inertValue, useEffectEvent, useId, useLayoutEffect, useResizeObserver} from '@react-aria/utils';
// @ts-ignore
import intlMessages from '../intl/*.json';
import {mergeStyles} from '../style/runtime';
import {pressScale} from './pressScale';
import {Text, TextContext} from './Content';
import {useDOMRef} from '@react-spectrum/utils';
Expand Down Expand Up @@ -473,10 +474,6 @@ const tagStyles = style<TagRenderProps & {size?: 'S' | 'M' | 'L', isEmphasized?:
cursor: {
default: 'default',
isLink: 'pointer'
},
'--iconPrimary': {
type: 'fill',
value: 'currentColor'
}
});

Expand Down Expand Up @@ -530,7 +527,7 @@ function TagWrapper({children, isDisabled, allowsRemoving, isInRealDOM, isEmphas
[TextContext, {styles: style({order: 1, truncate: true})}],
[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}))
}],
[AvatarContext, {
size: avatarSize[size],
Expand Down
Loading