Skip to content

Commit 8aeaca9

Browse files
fix: replace defaultProps with function default parameters (#2045)
1 parent 43bead5 commit 8aeaca9

File tree

73 files changed

+265
-564
lines changed

Some content is hidden

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

73 files changed

+265
-564
lines changed

docs/api.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ ensuring the details live up to expectations.
6666
`${componentStyles}` which allows an implementer to leverage the
6767
[`theme`](https://zendeskgarden.github.io/react-components/theming/)
6868
"components" object to override specific component styles.
69-
- The view component `defaultProps` must contain `theme: DEFAULT_THEME` for
70-
cases when the component might be used outside the context of a
71-
`<ThemeProvider>`.
7269
- With the exception of embedded icons, view components do not return JSX.
7370

7471
## Element components

docs/documentation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ the standard rules for Garden element component documentation:
4141
API](https://garden.zendesk.com/components/select#dropdown) for an
4242
external linking example
4343
- Only add prop JSDoc to [TypeScript prop interfaces](typescript.md)
44-
- Refrain from documenting React `defaultProps`
4544
- Refrain from documenting styled components props
4645
- Use `@ignore` to prevent a prop from being added to generated documentation.
4746
Use this tag sparingly to hide internal-only APIs.

packages/.template/src/styled/Styled{{capitalize component}}.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,3 @@ export const Styled{{capitalize component}} = styled.div.attrs<IStyled{{capitali
8080
8181
${componentStyles};
8282
`;
83-
84-
Styled{{capitalize component}}.defaultProps = {
85-
theme: DEFAULT_THEME
86-
};

packages/accordions/src/elements/accordion/Accordion.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const AccordionComponent = forwardRef<HTMLDivElement, IAccordionProps>(
2121
children,
2222
isBare,
2323
isCompact,
24-
isAnimated,
24+
isAnimated = true,
2525
isExpandable,
26-
isCollapsible,
26+
isCollapsible = true,
2727
level,
2828
onChange,
2929
defaultExpandedSections,
@@ -103,11 +103,6 @@ const AccordionComponent = forwardRef<HTMLDivElement, IAccordionProps>(
103103

104104
AccordionComponent.displayName = 'Accordion';
105105

106-
AccordionComponent.defaultProps = {
107-
isAnimated: true,
108-
isCollapsible: true
109-
};
110-
111106
/**
112107
* @extends HTMLAttributes<HTMLDivElement>
113108
*/

packages/accordions/src/elements/stepper/Stepper.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ const StepperComponent = forwardRef<HTMLOListElement, IStepperProps>(
5757

5858
StepperComponent.displayName = 'Stepper';
5959

60-
StepperComponent.defaultProps = {
61-
activeIndex: DEFAULT_ACTIVE_INDEX
62-
};
63-
6460
/**
6561
* @extends OlHTMLAttributes<HTMLOListElement>
6662
*/

packages/accordions/src/styled/accordion/StyledPanel.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
*/
77

88
import styled, { css, ThemeProps, DefaultTheme } from 'styled-components';
9-
import {
10-
getLineHeight,
11-
componentStyles,
12-
DEFAULT_THEME,
13-
getColor
14-
} from '@zendeskgarden/react-theming';
9+
import { getLineHeight, componentStyles, getColor } from '@zendeskgarden/react-theming';
1510

1611
interface IStyledPanel {
1712
inert?: string;
@@ -58,10 +53,11 @@ const sizeStyles = (props: IStyledPanel & ThemeProps<DefaultTheme>) => {
5853
`;
5954
};
6055

61-
export const StyledPanel = styled.section.attrs<IStyledPanel>({
56+
export const StyledPanel = styled.section.attrs<IStyledPanel>(props => ({
6257
'data-garden-id': COMPONENT_ID,
63-
'data-garden-version': PACKAGE_VERSION
64-
})<IStyledPanel>`
58+
'data-garden-version': PACKAGE_VERSION,
59+
$isAnimated: props.$isAnimated ?? true
60+
}))<IStyledPanel>`
6561
display: grid;
6662
transition: ${props =>
6763
props.$isAnimated && 'padding 0.25s ease-in-out, grid-template-rows 0.25s ease-in-out'};
@@ -72,8 +68,3 @@ export const StyledPanel = styled.section.attrs<IStyledPanel>({
7268
7369
${componentStyles};
7470
`;
75-
76-
StyledPanel.defaultProps = {
77-
$isAnimated: true,
78-
theme: DEFAULT_THEME
79-
};

packages/avatars/src/elements/Avatar.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const AvatarComponent = forwardRef<HTMLElement, IAvatarProps>(
2828
children,
2929
foregroundColor,
3030
isSystem,
31-
size,
31+
size = 'medium',
3232
status,
3333
statusLabel,
3434
surfaceColor,
@@ -122,10 +122,6 @@ AvatarComponent.propTypes = {
122122
statusLabel: PropTypes.string
123123
};
124124

125-
AvatarComponent.defaultProps = {
126-
size: 'medium'
127-
};
128-
129125
/**
130126
* @extends HTMLAttributes<HTMLElement>
131127
*/

packages/avatars/src/elements/StatusIndicator.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
* @extends HTMLAttributes<HTMLElement>
3232
*/
3333
export const StatusIndicator = forwardRef<HTMLElement, IStatusIndicatorProps>(
34-
({ children, type, isCompact, 'aria-label': label, ...props }, ref) => {
34+
({ children, type = 'offline', isCompact, 'aria-label': label, ...props }, ref) => {
3535
let ClockIcon = ClockIcon16;
3636
let ArrowLeftIcon = ArrowLeftIcon16;
3737

@@ -80,7 +80,3 @@ StatusIndicator.propTypes = {
8080
type: PropTypes.oneOf(STATUS),
8181
isCompact: PropTypes.bool
8282
};
83-
84-
StatusIndicator.defaultProps = {
85-
type: 'offline'
86-
};

packages/avatars/src/styled/StyledAvatar.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import styled, { css, ThemeProps, keyframes, DefaultTheme } from 'styled-components';
9-
import { componentStyles, DEFAULT_THEME, getColor } from '@zendeskgarden/react-theming';
9+
import { componentStyles, getColor } from '@zendeskgarden/react-theming';
1010
import { math } from 'polished';
1111

1212
import { IAvatarProps, SIZE } from '../types';
@@ -180,10 +180,11 @@ export interface IStyledAvatarProps {
180180
/**
181181
* Accepts all `<figure>` props
182182
*/
183-
export const StyledAvatar = styled.figure.attrs({
183+
export const StyledAvatar = styled.figure.attrs<IStyledAvatarProps>(props => ({
184184
'data-garden-id': COMPONENT_ID,
185-
'data-garden-version': PACKAGE_VERSION
186-
})<IStyledAvatarProps>`
185+
'data-garden-version': PACKAGE_VERSION,
186+
$size: props.$size ?? 'medium'
187+
}))<IStyledAvatarProps>`
187188
display: inline-flex;
188189
position: relative;
189190
align-items: center;
@@ -231,8 +232,3 @@ export const StyledAvatar = styled.figure.attrs({
231232
232233
${componentStyles};
233234
`;
234-
235-
StyledAvatar.defaultProps = {
236-
$size: 'medium',
237-
theme: DEFAULT_THEME
238-
};

packages/avatars/src/styled/StyledStandaloneStatusIndicator.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,24 @@
66
*/
77

88
import styled from 'styled-components';
9-
import { componentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
9+
import { componentStyles } from '@zendeskgarden/react-theming';
1010

1111
import { getStatusSize, IStyledStatusIndicatorProps } from './utility';
1212
import { StyledStatusIndicatorBase } from './StyledStatusIndicatorBase';
1313

1414
const COMPONENT_ID = 'avatars.status-indicator.indicator';
1515

16-
export const StyledStandaloneStatusIndicator = styled(StyledStatusIndicatorBase).attrs({
16+
export const StyledStandaloneStatusIndicator = styled(
17+
StyledStatusIndicatorBase
18+
).attrs<IStyledStatusIndicatorProps>(props => ({
1719
'data-garden-id': COMPONENT_ID,
18-
'data-garden-version': PACKAGE_VERSION
19-
})<IStyledStatusIndicatorProps>`
20+
'data-garden-version': PACKAGE_VERSION,
21+
$type: props.$type ?? 'offline'
22+
}))<IStyledStatusIndicatorProps>`
2023
position: relative;
2124
box-sizing: content-box;
2225
margin-top: ${props =>
2326
`calc((${props.theme.lineHeights.md} - ${getStatusSize(props, '0')}) / 2)`};
2427
2528
${componentStyles};
2629
`;
27-
28-
StyledStandaloneStatusIndicator.defaultProps = {
29-
$type: 'offline',
30-
theme: DEFAULT_THEME
31-
};

0 commit comments

Comments
 (0)