Skip to content

Commit bcbb17c

Browse files
authored
refactor(draggable, modals, typography): use transient props where appropriate (#1963)
1 parent 7c493fe commit bcbb17c

Some content is hidden

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

51 files changed

+343
-280
lines changed

packages/draggable/src/elements/draggable-list/DraggableList.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ import { StyledDraggableList } from '../../styled';
1212
import { IDraggableListProps } from '../../types';
1313
import { DraggableListContext } from '../../utils/useDraggableListContext';
1414

15-
const DraggableListComponent = forwardRef<HTMLUListElement, IDraggableListProps>((props, ref) => {
16-
const value = useMemo(() => ({ isHorizontal: props.isHorizontal }), [props.isHorizontal]);
15+
const DraggableListComponent = forwardRef<HTMLUListElement, IDraggableListProps>(
16+
({ isHorizontal, ...other }, ref) => {
17+
const value = useMemo(() => ({ isHorizontal }), [isHorizontal]);
1718

18-
return (
19-
<DraggableListContext.Provider value={value}>
20-
<StyledDraggableList {...props} ref={ref} />
21-
</DraggableListContext.Provider>
22-
);
23-
});
19+
return (
20+
<DraggableListContext.Provider value={value}>
21+
<StyledDraggableList $isHorizontal={isHorizontal} ref={ref} {...other} />
22+
</DraggableListContext.Provider>
23+
);
24+
}
25+
);
2426

2527
DraggableListComponent.displayName = 'DraggableList';
2628

packages/draggable/src/elements/draggable-list/components/DropIndicator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const DropIndicator = forwardRef<HTMLLIElement, LiHTMLAttributes<HTMLLIEl
2222
<StyledDropIndicator
2323
{...props}
2424
aria-label={ariaLabel}
25-
isHorizontal={isHorizontal}
25+
$isHorizontal={isHorizontal}
2626
ref={ref}
2727
/>
2828
);

packages/draggable/src/elements/draggable-list/components/Item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useDraggableListContext } from '../../../utils/useDraggableListContext'
1515
export const Item = forwardRef<HTMLLIElement, LiHTMLAttributes<HTMLLIElement>>((props, ref) => {
1616
const { isHorizontal } = useDraggableListContext();
1717

18-
return <StyledItem {...props} isHorizontal={isHorizontal} ref={ref} />;
18+
return <StyledItem {...props} $isHorizontal={isHorizontal} ref={ref} />;
1919
});
2020

2121
Item.displayName = 'DraggableList.Item';

packages/draggable/src/elements/draggable/Draggable.tsx

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,38 @@ import { Grip } from './components/Grip';
1111
import { StyledDraggable } from '../../styled';
1212
import { IDraggableProps } from '../../types';
1313

14-
const DraggableComponent = forwardRef<HTMLDivElement, IDraggableProps>(({ tag, ...props }, ref) => {
15-
const isDisabled = props.isDisabled;
14+
const DraggableComponent = forwardRef<HTMLDivElement, IDraggableProps>(
15+
(
16+
{
17+
focusInset,
18+
isBare,
19+
isCompact,
20+
isDisabled,
21+
isGrabbed,
22+
isPlaceholder,
1623

17-
return (
18-
<StyledDraggable
19-
as={tag}
20-
aria-disabled={isDisabled}
21-
tabIndex={isDisabled ? undefined : 0}
22-
{...props}
23-
ref={ref}
24-
/>
25-
);
26-
});
24+
tag,
25+
...other
26+
},
27+
ref
28+
) => {
29+
return (
30+
<StyledDraggable
31+
$focusInset={focusInset}
32+
$isBare={isBare}
33+
$isCompact={isCompact}
34+
$isDisabled={isDisabled}
35+
$isGrabbed={isGrabbed}
36+
$isPlaceholder={isPlaceholder}
37+
aria-disabled={isDisabled}
38+
as={tag}
39+
ref={ref}
40+
tabIndex={isDisabled ? undefined : 0}
41+
{...other}
42+
/>
43+
);
44+
}
45+
);
2746

2847
DraggableComponent.displayName = 'Draggable';
2948

packages/draggable/src/elements/dropzone/Dropzone.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { IDropzoneProps } from '../../types';
1414
import { DropzoneContext } from '../../utils/useDropzoneContext';
1515

1616
const DropzoneComponent = forwardRef<HTMLDivElement, IDropzoneProps>(
17-
({ tag, isVertical, children, ...props }, ref) => {
18-
const { isDanger } = props;
17+
({ children, isActive, isDanger, isDisabled, isHighlighted, isVertical, tag, ...other }, ref) => {
1918
const [hasMessage, setHasMessage] = useState(false);
2019
const [hasIcon, setHasIcon] = useState(false);
2120
const value = useMemo(
@@ -30,16 +29,20 @@ const DropzoneComponent = forwardRef<HTMLDivElement, IDropzoneProps>(
3029
<DropzoneContext.Provider value={value}>
3130
<StyledDropzone
3231
as={tag}
33-
aria-disabled={props.isDisabled}
34-
{...props}
35-
hasIcon={hasIcon}
36-
hasMessage={hasMessage}
37-
isVertical={isVertical}
32+
aria-disabled={isDisabled}
33+
{...other}
34+
$isActive={isActive}
35+
$isDisabled={isDisabled}
36+
$isDanger={isDanger}
37+
$isHighlighted={isHighlighted}
38+
$hasIcon={hasIcon}
39+
$hasMessage={hasMessage}
40+
$isVertical={isVertical}
3841
ref={ref}
3942
>
4043
{/* [1] */}
4144
{!!(hasMessage && isDanger) && !hasIcon && (
42-
<StyledIcon aria-hidden="true" hasMessage={hasMessage} isVertical={isVertical}>
45+
<StyledIcon aria-hidden="true" $hasMessage={hasMessage} $isVertical={isVertical}>
4346
<TrashIcon />
4447
</StyledIcon>
4548
)}

packages/draggable/src/elements/dropzone/components/Icon.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export const Icon = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>((
3131
<StyledIcon
3232
aria-hidden="true"
3333
{...props}
34-
hasMessage={hasMessage}
35-
isVertical={isVertical}
34+
$hasMessage={hasMessage}
35+
$isVertical={isVertical}
3636
ref={ref}
3737
/>
3838
);

packages/draggable/src/styled/draggable-list/StyledDraggableList.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import { StyledItem } from './StyledItem';
1212
const COMPONENT_ID = 'draggable_list';
1313

1414
export interface IStyledDraggableListProps extends ThemeProps<DefaultTheme> {
15-
isHorizontal?: boolean;
15+
$isHorizontal?: boolean;
1616
}
1717

1818
const sizeStyles = (props: IStyledDraggableListProps) => {
1919
const {
20-
isHorizontal,
20+
$isHorizontal,
2121
theme: { space }
2222
} = props;
2323
let marginStart = 'margin-top';
2424
let marginEnd = 'margin-bottom';
2525

26-
if (isHorizontal) {
26+
if ($isHorizontal) {
2727
marginStart = 'margin-right';
2828
marginEnd = 'margin-left';
2929
}
@@ -45,7 +45,7 @@ export const StyledDraggableList = styled.ul.attrs({
4545
'data-garden-version': PACKAGE_VERSION
4646
})<IStyledDraggableListProps & ThemeProps<DefaultTheme>>`
4747
display: flex;
48-
flex-direction: ${p => (p.isHorizontal ? 'row' : 'column')};
48+
flex-direction: ${p => (p.$isHorizontal ? 'row' : 'column')};
4949
margin: 0; /* [1] */
5050
padding: 0; /* [1] */
5151
list-style: none; /* [1] */

packages/draggable/src/styled/draggable-list/StyledDropIndicator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { retrieveComponentStyles, getColor } from '@zendeskgarden/react-theming'
1111
const COMPONENT_ID = 'draggable_list.drop_indicator';
1212

1313
export interface IStyledDropIndicatorProps extends ThemeProps<DefaultTheme> {
14-
isHorizontal?: boolean;
14+
$isHorizontal?: boolean;
1515
}
1616

1717
const colorStyles = (props: IStyledDropIndicatorProps) => {
@@ -33,10 +33,10 @@ const colorStyles = (props: IStyledDropIndicatorProps) => {
3333
};
3434

3535
const sizeStyles = (props: IStyledDropIndicatorProps) => {
36-
const { isHorizontal, theme } = props;
36+
const { $isHorizontal, theme } = props;
3737
const pseudoSize = theme.space.xs;
38-
const translateX = isHorizontal ? theme.space.xxs : theme.space.xs;
39-
const translateY = isHorizontal ? theme.space.xs : theme.space.xxs;
38+
const translateX = $isHorizontal ? theme.space.xxs : theme.space.xs;
39+
const translateY = $isHorizontal ? theme.space.xs : theme.space.xxs;
4040

4141
return css`
4242
&::before,

packages/draggable/src/styled/draggable-list/StyledItem.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import { retrieveComponentStyles } from '@zendeskgarden/react-theming';
1111
const COMPONENT_ID = 'draggable_list.item';
1212

1313
export interface IStyledItemProps extends ThemeProps<DefaultTheme> {
14-
isHorizontal?: boolean;
14+
$isHorizontal?: boolean;
1515
}
1616

1717
const sizeStyles = (props: IStyledItemProps) => {
1818
const {
19-
isHorizontal,
19+
$isHorizontal,
2020
theme: { space }
2121
} = props;
2222

2323
return css`
24-
padding: ${isHorizontal ? `0 ${space.xxs}` : `${space.xxs} 0`};
24+
padding: ${$isHorizontal ? `0 ${space.xxs}` : `${space.xxs} 0`};
2525
`;
2626
};
2727

packages/draggable/src/styled/draggable/StyledDraggable.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ describe('StyledDraggable', () => {
2424
});
2525

2626
it('applies grabbing cursor when grabbed', () => {
27-
const { container } = render(<StyledDraggable isGrabbed />);
27+
const { container } = render(<StyledDraggable $isGrabbed />);
2828

2929
expect(container.firstChild).toHaveStyle('cursor: grabbing');
3030
});
3131

3232
it('applies default cursor when disabled', () => {
33-
const { container } = render(<StyledDraggable isDisabled />);
33+
const { container } = render(<StyledDraggable $isDisabled />);
3434

3535
expect(container.firstChild).toHaveStyle('cursor: default');
3636
});
3737

3838
it('applies default cursor when placeholder', () => {
39-
const { container } = render(<StyledDraggable isPlaceholder />);
39+
const { container } = render(<StyledDraggable $isPlaceholder />);
4040

4141
expect(container.firstChild).toHaveStyle('cursor: default');
4242
});

0 commit comments

Comments
 (0)