Skip to content

Commit a629568

Browse files
Migrate components default props usage (#3027)
* refactor(design-system): migrate design system components * refactor(design-system): migrate vrt utility components * refactor(design-system): migrate calendar-utils components * refactor(design-system): migrate butons components * refactor(design-system): migrate collapsible components * refactor(design-system): migrate data table components * refactor(design-system): migrate spacings components * refactor(design-system): migrate input components * refactor(inputs): adjust missing parts * refactor: adjust the rest of the components * refactor: adjust default props on pending components * chore: remove files * chore: remove files
1 parent 791a094 commit a629568

File tree

78 files changed

+1264
-1172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1264
-1172
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ end_of_line = lf
88
indent_size = 2
99
indent_style = space
1010
insert_final_newline = true
11-
trim_trailing_whitespace = true
11+
trim_trailing_whitespace = true

design-system/src/theme-provider.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ const applyTheme = ({
6565
};
6666

6767
type ThemeProviderProps = {
68-
parentSelector: typeof defaultParentSelector;
69-
theme: string;
68+
parentSelector?: typeof defaultParentSelector;
69+
theme?: string;
7070
themeOverrides?: Record<string, string>;
7171
};
7272

73-
const ThemeProvider = (props: ThemeProviderProps) => {
74-
const parentSelectorRef = useRef(props.parentSelector);
73+
const ThemeProvider = ({
74+
parentSelector = defaultParentSelector,
75+
theme = 'default',
76+
...props
77+
}: ThemeProviderProps) => {
78+
const parentSelectorRef = useRef(parentSelector);
7579
const themeNameRef = useRef<string>();
7680
const themeOverridesRef = useRef<Record<string, string>>();
7781

@@ -80,26 +84,22 @@ const ThemeProvider = (props: ThemeProviderProps) => {
8084
// provided include a new object with the same theme overrides
8185
// (eg: users providing an inline object as prop to the ThemeProvider)
8286
if (
83-
themeNameRef.current !== props.theme ||
87+
themeNameRef.current !== theme ||
8488
!isEqual(themeOverridesRef.current, props.themeOverrides)
8589
) {
86-
themeNameRef.current = props.theme;
90+
themeNameRef.current = theme;
8791
themeOverridesRef.current = props.themeOverrides;
8892

8993
applyTheme({
90-
newTheme: props.theme,
94+
newTheme: theme,
9195
parentSelector: parentSelectorRef.current,
9296
themeOverrides: props.themeOverrides,
9397
});
9498
}
95-
}, [props.theme, props.themeOverrides]);
99+
}, [theme, props.themeOverrides]);
96100

97101
return null;
98102
};
99-
ThemeProvider.defaultProps = {
100-
parentSelector: defaultParentSelector,
101-
theme: 'default',
102-
};
103103

104104
type TUseThemeResult = {
105105
theme: ThemeName;

packages/calendar-utils/src/calendar-body/calendar-body.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ export type TCalendarBody = {
7979
theme?: Theme;
8080
};
8181

82-
const defaultProps: Pick<TCalendarBody, 'isClearable'> = {
83-
isClearable: true,
84-
};
85-
86-
export const CalendarBody = (props: TCalendarBody) => {
82+
export const CalendarBody = ({
83+
isClearable = true,
84+
...props
85+
}: TCalendarBody) => {
8786
const [isFocused, toggleIsFocused] = useToggleState(false);
8887

8988
const onInputFocus = props.inputProps?.onFocus;
@@ -130,18 +129,29 @@ export const CalendarBody = (props: TCalendarBody) => {
130129

131130
return (
132131
<Inline alignItems="center">
133-
<div css={getInputContainerStyles(props, { isFocused })}>
132+
<div
133+
css={getInputContainerStyles(
134+
{
135+
isClearable,
136+
...props,
137+
},
138+
{ isFocused }
139+
)}
140+
>
134141
<input
135142
ref={props.inputRef}
136143
{...props.inputProps}
137144
disabled={props.isDisabled}
138145
readOnly={props.isReadOnly}
139-
css={getDateTimeInputStyles(props)}
146+
css={getDateTimeInputStyles({
147+
isClearable,
148+
...props,
149+
})}
140150
onFocus={handleInputFocus}
141151
onBlur={handleInputBlur}
142152
aria-readonly={props.isReadOnly}
143153
/>
144-
{!disabledOrReadOnly && props.hasSelection && props.isClearable && (
154+
{!disabledOrReadOnly && props.hasSelection && isClearable && (
145155
<ClearSection
146156
isCondensed={props.isCondensed}
147157
hasError={props.hasError}
@@ -153,7 +163,13 @@ export const CalendarBody = (props: TCalendarBody) => {
153163
)}
154164
<button
155165
type="button"
156-
css={getCalendarIconContainerStyles(props, { isFocused })}
166+
css={getCalendarIconContainerStyles(
167+
{
168+
isClearable,
169+
...props,
170+
},
171+
{ isFocused }
172+
)}
157173
{...props.toggleButtonProps}
158174
onFocus={handleToggleFocus}
159175
onBlur={handleToggleBlur}
@@ -178,6 +194,4 @@ export const CalendarBody = (props: TCalendarBody) => {
178194

179195
CalendarBody.displayName = 'CalendarBody';
180196

181-
CalendarBody.defaultProps = defaultProps;
182-
183197
export default CalendarBody;

packages/components/avatar/src/avatar.tsx

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,6 @@ export type TInitialsProps = Pick<
4848
'firstName' | 'lastName' | 'size'
4949
>;
5050

51-
const defaultProps: Pick<
52-
TAvatarProps,
53-
'firstName' | 'lastName' | 'isHighlighted' | 'size' | 'color'
54-
> = {
55-
firstName: '',
56-
lastName: '',
57-
isHighlighted: false,
58-
size: 's',
59-
color: 'accent',
60-
};
61-
6251
const getFirstChar = (str: string) =>
6352
typeof str === 'string' ? str.trim().slice(0, 1).toUpperCase() : '';
6453

@@ -127,11 +116,35 @@ const Initials = (props: TInitialsProps) => {
127116
};
128117
Initials.displayName = 'Initials';
129118

130-
const Avatar = (props: TAvatarProps) => {
131-
const avatarSize = getWidthSize(props.size);
132-
const foregroundColor = getForegroundColor(props.color);
119+
const Avatar = ({
120+
firstName = '',
121+
lastName = '',
122+
isHighlighted = false,
123+
size = 's',
124+
color = 'accent',
125+
...props
126+
}: TAvatarProps) => {
127+
const avatarSize = getWidthSize(size);
128+
const foregroundColor = getForegroundColor(color);
133129
return (
134-
<div css={getAvatarStyles(props)} {...filterDataAttributes(props)}>
130+
<div
131+
css={getAvatarStyles({
132+
firstName,
133+
lastName,
134+
isHighlighted,
135+
size,
136+
color,
137+
...props,
138+
})}
139+
{...filterDataAttributes({
140+
firstName,
141+
lastName,
142+
isHighlighted,
143+
size,
144+
color,
145+
...props,
146+
})}
147+
>
135148
{props?.icon ? (
136149
<div
137150
css={css`
@@ -149,20 +162,15 @@ const Avatar = (props: TAvatarProps) => {
149162
<>
150163
<GravatarImg
151164
gravatarHash={props.gravatarHash}
152-
size={props.size}
153-
isHighlighted={props.isHighlighted}
154-
/>
155-
<Initials
156-
size={props.size}
157-
firstName={props.firstName}
158-
lastName={props.lastName}
165+
size={size}
166+
isHighlighted={isHighlighted}
159167
/>
168+
<Initials size={size} firstName={firstName} lastName={lastName} />
160169
</>
161170
)}
162171
</div>
163172
);
164173
};
165174
Avatar.displayName = 'Avatar';
166-
Avatar.defaultProps = defaultProps;
167175

168176
export default Avatar;

packages/components/buttons/accessible-button/src/accessible-button.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,29 @@ export type TAccessibleButtonProps = {
8484
buttonAttributes?: Record<string, unknown>;
8585
};
8686

87-
const defaultProps: Pick<
88-
TAccessibleButtonProps,
89-
'type' | 'buttonAttributes' | 'isToggleButton' | 'isToggled'
90-
> = {
91-
type: 'button',
92-
buttonAttributes: {},
93-
isToggleButton: false,
94-
isToggled: false,
95-
};
96-
9787
const AccessibleButton = forwardRef<HTMLButtonElement, TAccessibleButtonProps>(
98-
(props: TAccessibleButtonProps, ref) => {
88+
(
89+
{
90+
type = 'button',
91+
buttonAttributes = {},
92+
isToggleButton = false,
93+
isToggled = false,
94+
...props
95+
}: TAccessibleButtonProps,
96+
ref
97+
) => {
9998
warning(
10099
props.as ? isValidElementType(props.as) : true,
101100
`ui-kit/AccessibleButton: "as" must be a valid element type.`
102101
);
103102

104103
warning(
105-
!(props.as && props.type !== 'button'),
104+
!(props.as && type !== 'button'),
106105
`ui-kit/AccessibleButton: "type" does not have any effect when "as" is set.`
107106
);
108107

109108
warning(
110-
!(props.isToggleButton && props.isToggled === undefined),
109+
!(isToggleButton && isToggled === undefined),
111110
`ui-kit/AccessibleButton: "isToggled" is required if "isToggleButton" is "true"`
112111
);
113112

@@ -144,7 +143,7 @@ const AccessibleButton = forwardRef<HTMLButtonElement, TAccessibleButtonProps>(
144143
let buttonProps = {};
145144
if (isButton) {
146145
buttonProps = {
147-
type: props.type,
146+
type: type,
148147
};
149148
} else {
150149
buttonProps = {
@@ -177,8 +176,8 @@ const AccessibleButton = forwardRef<HTMLButtonElement, TAccessibleButtonProps>(
177176
className={props.className}
178177
disabled={props.isDisabled}
179178
aria-disabled={props.isDisabled}
180-
{...(props.isToggleButton ? { 'aria-pressed': props.isToggled } : {})}
181-
{...omit(props.buttonAttributes, propsToOmit)}
179+
{...(isToggleButton ? { 'aria-pressed': isToggled } : {})}
180+
{...omit(buttonAttributes, propsToOmit)}
182181
{...buttonProps}
183182
{...filterAriaAttributes(props)}
184183
{...filterDataAttributes(props)}
@@ -189,6 +188,5 @@ const AccessibleButton = forwardRef<HTMLButtonElement, TAccessibleButtonProps>(
189188
}
190189
);
191190
AccessibleButton.displayName = 'AccessibleButton';
192-
AccessibleButton.defaultProps = defaultProps;
193191

194192
export default AccessibleButton;

0 commit comments

Comments
 (0)