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

refactor!: rebrand Chip & ChipGroup components #1948

Merged
merged 14 commits into from
Jan 16, 2024
1 change: 1 addition & 0 deletions packages/blade/.storybook/react/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const config: StorybookConfig = {
'../../src/components/Indicator/**/*.stories.@(ts|tsx|js|jsx)',
'../../src/components/Button/**/*.stories.@(ts|tsx|js|jsx)',
'../../src/components/Divider/**/*.stories.@(ts|tsx|js|jsx)',
'../../src/components/Chip/**/*.stories.@(ts|tsx|js|jsx)',
'../../src/components/Carousel/**/*.stories.@(ts|tsx|js|jsx)',
'../../src/components/List/**/*.stories.@(ts|tsx|js|jsx)',
'../../src/components/Link/**/*.stories.@(ts|tsx|js|jsx)',
Expand Down
2 changes: 2 additions & 0 deletions packages/blade/rebranded-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const rebrandedComponents = [
'Link',
'Popover',
'Counter',
'Chip',
'ChipGroup',
'Badge',
'Indicator',
'IconButton',
Expand Down
4 changes: 2 additions & 2 deletions packages/blade/src/components/Chip/AnimatedChip.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const AnimatedChip = ({
}: Omit<AnimatedChipProps, 'theme'>): React.ReactElement => {
const { theme } = useTheme();

const easing = getIn(theme, chipMotionTokens.easing);
const duration = getIn(theme, chipMotionTokens.duration);
const easing = getIn(theme.motion, chipMotionTokens.easing);
Copy link
Collaborator

Choose a reason for hiding this comment

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

was this broken earlier?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, just refactored types as per #1948 (comment)

const duration = getIn(theme.motion, chipMotionTokens.duration);

const chipAnimation = useAnimatedStyle(() => {
return {
Expand Down
6 changes: 4 additions & 2 deletions packages/blade/src/components/Chip/AnimatedChip.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { makeMotionTime } from '~utils/makeMotionTime';
import { castWebType } from '~utils';

const AnimatedChip = styled(BaseBox)<AnimatedChipProps>((props) => {
const easing = getIn(props.theme, chipMotionTokens.easing);
const duration = castWebType(makeMotionTime(getIn(props.theme, chipMotionTokens.duration)));
const easing = getIn(props.theme.motion, chipMotionTokens.easing);
const duration = castWebType(
makeMotionTime(getIn(props.theme.motion, chipMotionTokens.duration)),
);
return {
...getAnimatedChipStyles(props),
width: 'fit-content',
Expand Down
19 changes: 3 additions & 16 deletions packages/blade/src/components/Chip/Chip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,16 @@ export default {
},
},
},
intent: {
description: 'This is deprecated in favor of the `color` prop.',
table: {
category: propsCategory.CHIP,
type: {
summary: '"none" | "positive" | "negative"',
},
},
options: ['none', 'positive', 'negative'],
control: {
type: 'radio',
},
},
color: {
description:
'Sets the color of the Chip. This overwrites the color set by the parent `ChipGroup` component',
table: {
category: propsCategory.CHIP,
type: {
summary: '"default" | "positive" | "negative"',
summary: '"primary" | "positive" | "negative"',
},
},
options: ['default', 'positive', 'negative'],
options: ['primary', 'positive', 'negative'],
control: {
type: 'radio',
},
Expand Down Expand Up @@ -133,5 +120,5 @@ const ChipTemplate: StoryFn<typeof ChipComponent> = ({ children, ...args }) => {
export const Default = ChipTemplate.bind({});
Default.storyName = 'Default';
Default.args = {
color: 'default',
color: 'primary',
};
22 changes: 7 additions & 15 deletions packages/blade/src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type OnChange = ({
}) => void;

const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
{ isDisabled, value, children, icon: Icon, intent, color, testID, ...styledProps },
{ isDisabled, value, children, icon: Icon, color, testID, ...styledProps },
ref,
) => {
const { theme } = useTheme();
Expand Down Expand Up @@ -67,10 +67,7 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
: groupProps?.defaultValue?.includes(value as string); // If multiple selection, check if value is in defaultValue array
const useChip = groupProps?.selectionType === 'single' ? useRadio : useCheckbox;
const _size = groupProps?.size || 'small';
const _intent = intent ?? groupProps?.intent;
// If intent is proovided and it's not none, use intent otherwise use color
const _color = color ?? groupProps?.color ?? 'default';
const chipColor = _intent && _intent !== 'none' ? _intent : _color;
const chipColor = color ?? groupProps?.color ?? 'primary';

const handleChange: OnChange = ({ isChecked, value }) => {
if (isChecked) {
Expand Down Expand Up @@ -129,13 +126,13 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
const chipTextColor = chipColorTokens.text[textVariant];
const chipIconColor = chipColorTokens.icon[textVariant];

let intentVariant = 'unchecked';
let colorVariant = 'unchecked';
const stateVariant = _isDisabled ? 'disabled' : 'default';
if (_isChecked && chipColor) {
intentVariant = chipColor;
colorVariant = chipColor;
}
const chipBackgroundColor = chipColorTokens.background[intentVariant][stateVariant];
const chipBorderColor = chipColorTokens.border[intentVariant][stateVariant];
const chipBackgroundColor = chipColorTokens.background[colorVariant][stateVariant];
const chipBorderColor = chipColorTokens.border[colorVariant][stateVariant];

return (
<BaseBox
Expand Down Expand Up @@ -200,12 +197,7 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
<Icon color={chipIconColor} size={chipIconSizes[_size]} />
</BaseBox>
) : null}
<Text
{...chipTextSizes[_size]}
type="normal"
truncateAfterLines={1}
color={chipTextColor}
>
<Text {...chipTextSizes[_size]} truncateAfterLines={1} color={chipTextColor}>
{children}
</Text>
</StyledChipWrapper>
Expand Down
Loading
Loading