Skip to content

Commit 361ac6e

Browse files
author
Kubit
committed
Refactor actionBottomSheet and Create modal v2
Refactored the actionBottomSheet component to improve code readability and maintainability. Created a new modal v2 component with enhanced features and better performance. Updated relevant tests and documentation to reflect the changes.
1 parent 2698076 commit 361ac6e

31 files changed

+1422
-44
lines changed

src/components/actionBottomSheet/actionBottomSheet.styled.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ export const ActionBottomSheetHeaderStyled = styled.div<IActionBottomSheetStyles
2525
${props => getStyles(props.styles)}
2626
`;
2727

28+
export const ActionBottomSheetControlStyled = styled.div<IActionBottomSheetStyles>`
29+
${props => getStyles(props.styles)}
30+
`;
31+
32+
export const ActionBottomSheetActionStyled = styled.div<IActionBottomSheetStyles>`
33+
${props => getStyles(props.styles)}
34+
`;
35+
2836
export const ActionBottomSheetIconSyled = styled.div<IActionBottomSheetStyles>`
2937
display: flex;
3038
${props => getStyles(props.styles)}

src/components/actionBottomSheet/actionBottomSheetControlled.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ const ActionBottomSheetControlledStructureComponent = React.forwardRef(
3030
);
3131
const device = useMediaDevice();
3232

33-
const condition = React.useMemo(
33+
const conditional = React.useMemo(
3434
() =>
3535
device !== DeviceBreakpointsType.DESKTOP && device !== DeviceBreakpointsType.LARGE_DESKTOP,
3636
[device]
3737
);
3838

39-
const { scrollableRef, shadowRef } = useScrollEffect(
40-
condition,
41-
styles.header?.[device]?.box_shadow,
42-
SCROLL_DISTANCE
43-
);
39+
const { scrollableRef, shadowRef } = useScrollEffect({
40+
conditional,
41+
shadowStyles: styles.controlContainer?.[device]?.box_shadow,
42+
shadowVisible: SCROLL_DISTANCE,
43+
});
4444

4545
return (
4646
<ActionBottomSheetStandAlone

src/components/actionBottomSheet/actionBottomSheetStandAlone.tsx

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import { ElementOrIcon } from '@/components/elementOrIcon';
44
import { Text } from '@/components/text/text';
55
import { TextComponentType } from '@/components/text/types/component';
66

7+
import { Link } from '../link';
78
import {
9+
ActionBottomSheetActionStyled,
810
ActionBottomSheetContentStyled,
11+
ActionBottomSheetControlStyled,
912
ActionBottomSheetHeaderContentStyled,
1013
ActionBottomSheetHeaderStyled,
1114
ActionBottomSheetIconSyled,
@@ -18,40 +21,60 @@ const ActionBottomSheetStandAloneComponent = (
1821
{ hasHeader = true, scrollableRef, shadowRef, ...props }: IActionBottomSheetStandAlone,
1922
ref: React.ForwardedRef<HTMLDivElement> | undefined | null
2023
): JSX.Element => {
24+
// Parent container Ref
25+
const actionBottomRef = React.useRef<HTMLDivElement | null>(null);
26+
27+
// Expose the ref to the parent component
28+
React.useImperativeHandle(ref, () => {
29+
return actionBottomRef.current as HTMLDivElement;
30+
}, []);
31+
32+
// Set the parent componente ref for the scrollableRef function
33+
React.useEffect(() => {
34+
scrollableRef(actionBottomRef.current);
35+
}, []);
36+
2137
return (
2238
<ActionBottomSheetStyled
23-
ref={ref}
39+
ref={actionBottomRef}
2440
$height={props.height}
2541
data-testid={`${props.dataTestId}Container`}
2642
styles={props.styles.container}
2743
>
2844
{hasHeader && (
29-
<ActionBottomSheetHeaderStyled ref={shadowRef} styles={props.styles.header}>
30-
<ActionBottomSheetIconSyled styles={props.styles.closeIconContainer}>
31-
<ElementOrIcon
32-
customIconStyles={props.styles.closeIcon}
33-
dataTestId={`${props.dataTestId}Icon`}
34-
{...props.closeIcon}
35-
/>
36-
</ActionBottomSheetIconSyled>
37-
<ActionBottomSheetTitleSyled styles={props.styles}>
38-
<Text
39-
component={TextComponentType.H5}
40-
customTypography={props.styles.title}
41-
dataTestId={`${props.dataTestId}Title`}
42-
{...props.title}
43-
>
44-
{props.title?.content}
45-
</Text>
46-
</ActionBottomSheetTitleSyled>
47-
{props.headerContent && (
48-
<ActionBottomSheetHeaderContentStyled styles={props.styles}>
49-
{props.headerContent}
50-
</ActionBottomSheetHeaderContentStyled>
51-
)}
52-
</ActionBottomSheetHeaderStyled>
45+
<>
46+
<ActionBottomSheetControlStyled ref={shadowRef} styles={props.styles.controlContainer}>
47+
<ActionBottomSheetActionStyled styles={props.styles.actionLinkContainer}>
48+
{props.actionLink && <Link {...props.actionLink} />}
49+
</ActionBottomSheetActionStyled>
50+
<ActionBottomSheetIconSyled styles={props.styles.closeIconContainer}>
51+
<ElementOrIcon
52+
customIconStyles={props.styles.closeIcon}
53+
dataTestId={`${props.dataTestId}Icon`}
54+
{...props.closeIcon}
55+
/>
56+
</ActionBottomSheetIconSyled>
57+
</ActionBottomSheetControlStyled>
58+
<ActionBottomSheetHeaderStyled styles={props.styles.header}>
59+
<ActionBottomSheetTitleSyled styles={props.styles}>
60+
<Text
61+
component={TextComponentType.H5}
62+
customTypography={props.styles.title}
63+
dataTestId={`${props.dataTestId}Title`}
64+
{...props.title}
65+
>
66+
{props.title?.content}
67+
</Text>
68+
</ActionBottomSheetTitleSyled>
69+
{props.headerContent && (
70+
<ActionBottomSheetHeaderContentStyled styles={props.styles}>
71+
{props.headerContent}
72+
</ActionBottomSheetHeaderContentStyled>
73+
)}
74+
</ActionBottomSheetHeaderStyled>
75+
</>
5376
)}
54-
<ActionBottomSheetContentStyled ref={scrollableRef} styles={props.styles.content}>
77+
<ActionBottomSheetContentStyled styles={props.styles.content}>
5578
{props.children}
5679
</ActionBottomSheetContentStyled>
5780
</ActionBottomSheetStyled>

src/components/actionBottomSheet/stories/actionBottomSheet.stories.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ export const ActionBottomSheet: Story = {
4141
['aria-label']: 'ariaLabelButton',
4242
},
4343
headerContent: <ReplaceContent />,
44-
children: <ReplaceContent />,
44+
children: (
45+
<>
46+
<ReplaceContent />
47+
<ReplaceContent />
48+
<ReplaceContent />
49+
<ReplaceContent />
50+
<ReplaceContent />
51+
<ReplaceContent />
52+
</>
53+
),
4554
open: true,
4655
themeArgs: themesObject[themeSelected][STYLES_NAME.ACTION_BOTTOM_SHEET],
4756
},

src/components/actionBottomSheet/types/actionBottomSheet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { IElementOrIcon } from '@/components/elementOrIcon';
2+
import { ILink } from '@/components/link';
23
import { IPopoverControlled } from '@/components/popover';
34
import { IText } from '@/components/text';
45
import { CustomTokenTypes, DeviceBreakpointsType } from '@/types';
@@ -21,6 +22,7 @@ export interface IActionBottomSheetStandAlone {
2122
children: React.ReactNode;
2223
styles: ActionBottomSheetVariantStylesType;
2324
closeIcon?: IElementOrIcon;
25+
actionLink?: ILink;
2426
title?: ActionBottomSheetTextType;
2527
hasHeader?: boolean;
2628
dataTestId?: string;

src/components/actionBottomSheet/types/actionBottomSheetTheme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { CommonStyleType, IconTypes, TypographyTypes } from '@/types';
99
export type ActionBottomSheetVariantStylesType = {
1010
container?: CommonStyleType;
1111
header?: CommonStyleType;
12+
controlContainer?: CommonStyleType;
13+
actionLinkContainer?: CommonStyleType;
1214
closeIconContainer?: CommonStyleType;
1315
closeIcon?: IconTypes;
1416
titleContainer?: CommonStyleType;

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export * from './breadcrumbs';
3434
export * from './drawer';
3535
export * from './message';
3636
export * from './modal';
37+
export * from './modalV2';
3738
export * from './oliveMenu';
3839
export * from './pillSelector';
3940
export * from './pillSelectorV2';

src/components/modal/modalControlled.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ const ModalControlledComponent = React.forwardRef(
2727
const styles = useStyles<ModalBaseStylesType, V>(STYLES_NAME.MODAL, variant, ctv);
2828
const device = useMediaDevice();
2929

30-
const condition = React.useMemo(
30+
const conditional = React.useMemo(
3131
() =>
3232
device !== DeviceBreakpointsType.DESKTOP && device !== DeviceBreakpointsType.LARGE_DESKTOP,
3333
[device]
3434
);
35-
const { scrollableRef, resizeRef, shadowRef } = useScrollEffect(
36-
condition,
37-
styles.headerContainer?.box_shadow
38-
);
35+
const { scrollableRef, resizeRef, shadowRef } = useScrollEffect({
36+
conditional,
37+
shadowStyles: styles.headerContainer?.box_shadow,
38+
});
3939

4040
const zoomRef = useZoomEffect(CONTAINER_STYLES_EDIT, MAX_ZOOM);
4141
const zoomRefChild = useZoomEffect(CONTENT_STYLES_EDIT, MAX_ZOOM);

src/components/modal/stories/modal.stories.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,31 @@ const meta = {
2424
figmaUrl:
2525
'https://www.figma.com/file/EYQkbENTFO5r8muvXlPoOy/Kubit-v.1.0.0?type=design&node-id=3922-22906&mode=dev',
2626
},
27+
render: ({ ...args }) => <StoryWithHooks {...args} />,
2728
} satisfies Meta<typeof Story>;
2829

2930
export default meta;
3031

3132
type Story = StoryObj<typeof meta> & { args: { themeArgs?: object } };
3233

34+
const StoryWithHooks = args => {
35+
const [open, setOpen] = React.useState(false);
36+
37+
const handleClose = () => {
38+
setOpen(false);
39+
};
40+
const handleOpen = () => {
41+
setOpen(true);
42+
};
43+
44+
return (
45+
<div style={{ width: 'fit-content' }}>
46+
<button onClick={handleOpen}>Open Modal</button>
47+
<Story {...args} closeIcon={{ ...args.closeIcon, onClick: handleClose }} open={open} />
48+
</div>
49+
);
50+
};
51+
3352
export const Modal: Story = {
3453
args: {
3554
variant: Object.values(variantsObject[themeSelected].ModalVariantType || {})[0] as string,

0 commit comments

Comments
 (0)