Skip to content

Commit 40e189c

Browse files
lisalupimatthprost
authored andcommitted
feat: remove deprecated props in Icon CodeEditor and Bullet (#5297)
* feat: remove deprecated props Icon, CodeEditor and Bullet * fix: use current color by default on icon
1 parent f95c6d2 commit 40e189c

File tree

9 files changed

+79
-87
lines changed

9 files changed

+79
-87
lines changed

.changeset/yellow-ghosts-tease.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@ultraviolet/plus": major
3+
"@ultraviolet/icons": major
4+
"@ultraviolet/ui": major
5+
---
6+
7+
**BREAKING CHANGES**
8+
9+
Deprecated props removed:
10+
- `CodeEditor`: prop "title" removed -> use "label" instead
11+
- `Icon`: prop "color" removed -> use "sentiment" instead
12+
- `Icon`: prop "size" can only be "xsmall", "small", "medium", "large", "xlarge" or "xxlarge"
13+
- `Bullet`: prop "text" removed -> use "children" instead

packages/icons/src/components/Icon/Icon.tsx

Lines changed: 52 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const SIZES = {
1717
xxlarge: '700',
1818
} as const
1919

20+
type SizesProps = keyof typeof SIZES
21+
2022
type Color = Extract<
2123
keyof typeof theme.colors,
2224
| 'primary'
@@ -32,28 +34,14 @@ const sizeStyles = ({
3234
size,
3335
theme,
3436
}: {
35-
size: keyof typeof SIZES | number | string
37+
size: SizesProps
3638
theme: Theme
37-
}) => {
38-
if (typeof size === 'string' && size in SIZES) {
39-
return css`
40-
height: ${theme.sizing[SIZES[size as keyof typeof SIZES]]};
41-
width: ${theme.sizing[SIZES[size as keyof typeof SIZES]]};
42-
min-width: ${theme.sizing[SIZES[size as keyof typeof SIZES]]};
43-
min-height: ${theme.sizing[SIZES[size as keyof typeof SIZES]]};
39+
}) => css`
40+
height: ${theme.sizing[SIZES[size]]};
41+
width: ${theme.sizing[SIZES[size]]};
42+
min-width: ${theme.sizing[SIZES[size]]};
43+
min-height: ${theme.sizing[SIZES[size]]};
4444
`
45-
}
46-
47-
const pxSize =
48-
typeof size === 'number' && !Number.isNaN(size) ? `${size}px` : size
49-
50-
return css`
51-
height: ${pxSize};
52-
width: ${pxSize};
53-
min-width: ${pxSize};
54-
min-height: ${pxSize};
55-
`
56-
}
5745

5846
const PROMINENCES = {
5947
default: '',
@@ -68,8 +56,8 @@ const StyledIcon = styled('svg', {
6856
shouldForwardProp: prop =>
6957
!['size', 'sentiment', 'prominence', 'disabled'].includes(prop),
7058
})<{
71-
sentiment: Color | string
72-
size: number | string
59+
sentiment?: Color
60+
size: SizesProps
7361
prominence: ProminenceProps
7462
disabled?: boolean
7563
}>`
@@ -82,12 +70,16 @@ const StyledIcon = styled('svg', {
8270
? capitalize(PROMINENCES.default)
8371
: capitalize(PROMINENCES[prominence])
8472
85-
const themeColor = theme.colors[sentiment as Color]
86-
const icon = `icon${definedProminence}${
87-
disabled ? 'Disabled' : ''
88-
}` as keyof typeof themeColor
73+
if (sentiment) {
74+
const themeColor = theme.colors[sentiment]
75+
const icon = `icon${definedProminence}${
76+
disabled ? 'Disabled' : ''
77+
}` as keyof typeof themeColor
78+
79+
return theme.colors?.[sentiment]?.[icon] || sentiment
80+
}
8981
90-
return theme.colors?.[sentiment as Color]?.[icon] || sentiment
82+
return 'currentColor'
9183
}};
9284
9385
.fillStroke {
@@ -98,25 +90,25 @@ const StyledIcon = styled('svg', {
9890
? capitalize(PROMINENCES.default)
9991
: capitalize(PROMINENCES[prominence])
10092
101-
const themeColor = theme.colors[sentiment as Color]
102-
const icon = `icon${definedProminence}${
103-
disabled ? 'Disabled' : ''
104-
}` as keyof typeof themeColor
93+
if (sentiment) {
94+
const themeColor = theme.colors[sentiment]
95+
const icon = `icon${definedProminence}${
96+
disabled ? 'Disabled' : ''
97+
}` as keyof typeof themeColor
98+
99+
return theme.colors?.[sentiment]?.[icon] || sentiment
100+
}
105101
106-
return theme.colors?.[sentiment as Color]?.[icon] || sentiment
102+
return 'currentColor'
107103
}};
108104
fill: none;
109105
}
110106
${sizeStyles}
111107
`
112108

113109
export type IconProps = {
114-
size?: keyof typeof SIZES
110+
size?: SizesProps
115111
prominence?: ProminenceProps
116-
/**
117-
* @deprecated use `sentiment` property instead
118-
*/
119-
color?: Color
120112
sentiment?: Color
121113
'data-testid'?: string
122114
disabled?: boolean
@@ -127,13 +119,12 @@ export type IconProps = {
127119
>
128120

129121
/**
130-
* IconV2 component is our set of system icons in the design system. All of them are SVGs.
122+
* Icon component is our set of system icons in the design system. All of them are SVGs.
131123
*/
132124

133125
export const Icon = forwardRef<SVGSVGElement, IconProps>(
134126
(
135127
{
136-
color = 'currentColor',
137128
sentiment,
138129
size = 'small',
139130
prominence = 'default',
@@ -147,30 +138,26 @@ export const Icon = forwardRef<SVGSVGElement, IconProps>(
147138
children,
148139
},
149140
ref,
150-
) => {
151-
const computedSentiment = sentiment ?? color
152-
153-
return (
154-
<StyledIcon
155-
ref={ref}
156-
sentiment={computedSentiment}
157-
prominence={prominence}
158-
size={size}
159-
viewBox={
160-
typeof size === 'string' && ['xsmall', 'small'].includes(size)
161-
? '0 0 16 16'
162-
: '0 0 20 20'
163-
}
164-
className={className}
165-
data-testid={dataTestId}
166-
stroke={stroke}
167-
cursor={cursor}
168-
strokeWidth={strokeWidth}
169-
disabled={disabled}
170-
aria-label={ariaLabel}
171-
>
172-
{children}
173-
</StyledIcon>
174-
)
175-
},
141+
) => (
142+
<StyledIcon
143+
ref={ref}
144+
sentiment={sentiment}
145+
prominence={prominence}
146+
size={size}
147+
viewBox={
148+
typeof size === 'string' && ['xsmall', 'small'].includes(size)
149+
? '0 0 16 16'
150+
: '0 0 20 20'
151+
}
152+
className={className}
153+
data-testid={dataTestId}
154+
stroke={stroke}
155+
cursor={cursor}
156+
strokeWidth={strokeWidth}
157+
disabled={disabled}
158+
aria-label={ariaLabel}
159+
>
160+
{children}
161+
</StyledIcon>
162+
),
176163
)

packages/plus/src/components/CodeEditor/CodeEditor.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const EditorContainer = styled.div`
5151
user-select: none;
5252
5353
.cm-editor {
54-
background-color: ${consoleDarkTheme.colors.neutral.backgroundWeakDisabled};
54+
background-color: ${
55+
consoleDarkTheme.colors.neutral.backgroundWeakDisabled
56+
};
5557
color: ${consoleDarkTheme.colors.neutral.textDisabled};
5658
}
5759
@@ -103,10 +105,6 @@ const StyledCopyButton = styled(CopyButton)`
103105
`
104106

105107
type CodeEditorProps = {
106-
/**
107-
* @deprecated use prop `label` instead
108-
*/
109-
title?: string
110108
value: string
111109
onChange: ComponentProps<typeof CodeMirror>['onChange']
112110
extensions: keyof typeof langs
@@ -130,7 +128,6 @@ type CodeEditorProps = {
130128
}
131129

132130
export const CodeEditor = ({
133-
title,
134131
value,
135132
onChange,
136133
extensions = 'javascript',
@@ -149,9 +146,7 @@ export const CodeEditor = ({
149146
className,
150147
}: CodeEditorProps) => (
151148
<StyledStack gap={0.5} data-disabled={disabled}>
152-
{label || title ? (
153-
<Label labelDescription={labelDescription}>{label ?? title}</Label>
154-
) : null}
149+
{label ? <Label labelDescription={labelDescription}>{label}</Label> : null}
155150
<EditorContainer data-disabled={disabled}>
156151
<CodeMirror
157152
readOnly={readOnly || disabled}

packages/plus/src/components/CodeEditor/__tests__/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ describe.skip('CodeEditor', () => {
2020
/>,
2121
))
2222

23-
it('should render correctly with title', () =>
23+
it('should render correctly with label', () =>
2424
shouldMatchEmotionSnapshot(
2525
<CodeEditor
2626
value="configuration: 1/ntest: 'ok'"
2727
extensions="yaml"
2828
height="600px"
2929
onChange={newValue => newValue}
3030
helper="Helper text"
31-
title="title"
31+
label="title"
3232
/>,
3333
))
3434

packages/plus/src/components/FAQ/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const FAQ = ({
4141
<Stack gap={2} direction="row">
4242
<div>
4343
{!productIconName && illustrationText ? (
44-
<Bullet sentiment="primary" text={illustrationText.toString()} />
44+
<Bullet sentiment="primary">{illustrationText.toString()}</Bullet>
4545
) : null}
4646
{ProductIconUsed ? <ProductIconUsed size="xlarge" /> : null}
4747
</div>

packages/ui/src/components/Bullet/__stories__/Text.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Text.parameters = {
77
docs: {
88
description: {
99
story:
10-
'Set `text` using text property. Sentiment and size props affect text.',
10+
'Set `text` using children. Sentiment and size props affect children.',
1111
},
1212
},
1313
}

packages/ui/src/components/Bullet/__tests__/index.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { SENTIMENTS } from '../../../theme'
66

77
describe('Bullet', () => {
88
test('renders correctly with a text', () =>
9-
shouldMatchEmotionSnapshot(<Bullet text="1" />))
9+
shouldMatchEmotionSnapshot(<Bullet>1</Bullet>))
1010

1111
test('renders correctly with an icon', () =>
1212
shouldMatchEmotionSnapshot(
@@ -25,14 +25,14 @@ describe('Bullet', () => {
2525
describe('sentiment', () => {
2626
;['disabled', ...SENTIMENTS].forEach(sentiment => {
2727
test(`render ${sentiment}`, () =>
28-
shouldMatchEmotionSnapshot(<Bullet sentiment={sentiment} text="1" />))
28+
shouldMatchEmotionSnapshot(<Bullet sentiment={sentiment}>1</Bullet>))
2929
})
3030
})
3131

3232
describe('size', () => {
3333
;(['medium', 'small', 'xsmall', 'xxsmall'] as const).forEach(size => {
3434
test(`render ${size}`, () =>
35-
shouldMatchEmotionSnapshot(<Bullet size={size} text="1" />))
35+
shouldMatchEmotionSnapshot(<Bullet size={size}>1</Bullet>))
3636
})
3737
})
3838
})

packages/ui/src/components/Bullet/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ const StyledContainer = styled('div')<StyledContainerType>`
9393
align-items: center;
9494
width: ${({ size, theme }) => theme.sizing[SIZES[size]]};
9595
height: ${({ size, theme }) => theme.sizing[SIZES[size]]};
96-
font-size: ${({ size, theme }) => theme.typography[TEXT_VARIANT[size]].fontSize};
96+
font-size: ${({ size, theme }) =>
97+
theme.typography[TEXT_VARIANT[size]].fontSize};
9798
${({ theme, prominence, sentiment }) =>
9899
(sentimentStyles({ theme, prominence }) as Record<BulletSentiment, string>)[
99100
sentiment
@@ -109,8 +110,6 @@ type BulletProps = {
109110
'data-testid'?: string
110111
prominence?: ProminenceType
111112
children?: ReactNode
112-
/** @deprecated Use children instead */
113-
text?: string
114113
}
115114

116115
/**
@@ -120,7 +119,6 @@ export const Bullet = ({
120119
className,
121120
sentiment = 'neutral',
122121
size = 'medium',
123-
text,
124122
tooltip,
125123
tooltipBaseId,
126124
'data-testid': dataTestId,
@@ -135,7 +133,6 @@ export const Bullet = ({
135133
data-testid={dataTestId}
136134
prominence={prominence}
137135
>
138-
{text}
139136
{children}
140137
</StyledContainer>
141138
</Tooltip>

packages/ui/src/components/NumberInput/__stories__/LabelDescription.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const LabelDescription: StoryFn = (
2121
label="Advanced Label"
2222
labelDescription={
2323
<Tooltip text="Tooltip message">
24-
<AlertCircleOutlineIcon color="neutral" />
24+
<AlertCircleOutlineIcon sentiment="neutral" />
2525
</Tooltip>
2626
}
2727
required

0 commit comments

Comments
 (0)