Skip to content

Commit c4d5c93

Browse files
committed
refactor(bottomsheet): API props + docs improvements
Signed-off-by: Simon Bruneaud <[email protected]>
1 parent 78c90f2 commit c4d5c93

File tree

7 files changed

+53
-61
lines changed

7 files changed

+53
-61
lines changed

apps/app-sandbox-rnative/src/app/blocks/BottomSheets.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const BottomSheets = forwardRef<React.ElementRef<typeof BottomSheet>>(
2424
}));
2525

2626
return (
27-
<BottomSheet {...props} ref={ref} closeable>
27+
<BottomSheet {...props} ref={ref}>
2828
<BottomSheetHeader
2929
spacing
3030
title='Virtual List'

libs/ui-rnative/src/lib/Components/BottomSheet/BottomSheet.mdx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ When using dynamic sizing with potentially long content, set `maxDynamicContentS
8080

8181
<Canvas of={BottomSheetStories.DynamicSizingAndMaxSize} />
8282

83-
### Non-Closeable
83+
### Hidden Close Button
8484

85-
Prevent user dismissal for critical flows where users must complete an action or make a decision. Set both `closeable={false}` and `enablePanDownToClose={false}` to disable all dismiss mechanisms. Use this pattern for required confirmations, important notices, or multi-step processes. The sheet can only be closed programmatically via ref.
85+
Prevent user dismissal for critical flows where users must complete an action or make a decision. Set both `hideCloseButton={true}` and `enablePanDownToClose={false}` to disable all dismiss mechanisms. Use this pattern for required confirmations, important notices, or multi-step processes. The sheet can only be closed programmatically via ref.
8686

87-
<Canvas of={BottomSheetStories.NonCloseable} />
87+
<Canvas of={BottomSheetStories.HiddenCloseButton} />
8888

8989
## Accessibility
9090

@@ -119,7 +119,7 @@ function MyComponent() {
119119
Open Bottom Sheet
120120
</Button>
121121

122-
<BottomSheet ref={bottomSheetRef} snapPoints="full" closeable>
122+
<BottomSheet ref={bottomSheetRef} snapPoints="full">
123123
<BottomSheetView>
124124
<BottomSheetHeader
125125
title="Welcome"
@@ -192,8 +192,8 @@ function MyComponent() {
192192
```tsx
193193
// Preset snap points
194194
<BottomSheet snapPoints="full"> {/* 95% of screen */}
195-
<BottomSheet snapPoints="half"> {/* 50% of screen */}
196-
<BottomSheet snapPoints="quarter"> {/* 25% of screen */}
195+
<BottomSheet snapPoints="medium"> {/* 50% of screen */}
196+
<BottomSheet snapPoints="small"> {/* 25% of screen */}
197197

198198
// Custom snap points (pixels, percentages, or mixed)
199199
<BottomSheet snapPoints={[200, 400, 600]}>
@@ -245,7 +245,10 @@ const bottomSheetRef = useBottomSheetRef();
245245
bottomSheetRef.current?.expand();
246246

247247
// Disable both for non-dismissible sheets
248-
<BottomSheet closeable={false} enablePanDownToClose={false}>
248+
<BottomSheet
249+
hideCloseButton
250+
enablePanDownToClose={false}
251+
>
249252
```
250253

251254
❌ **Don't**

libs/ui-rnative/src/lib/Components/BottomSheet/BottomSheet.stories.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ const meta = {
3030
options: [
3131
undefined,
3232
'full',
33-
'half',
34-
'quarter',
33+
'medium',
34+
'small',
3535
'[150, 300]',
3636
'["25%", "50%"]',
3737
],
3838
mapping: {
3939
undefined: undefined,
4040
full: 'full',
41-
half: 'half',
42-
quarter: 'quarter',
41+
medium: 'medium',
42+
small: 'small',
4343
'[150, 300]': [150, 300],
4444
'["25%", "50%"]': ['25%', '50%'],
4545
},
@@ -73,7 +73,7 @@ type Story = StoryObj<typeof BottomSheet>;
7373
export const Base: Story = {
7474
args: {
7575
snapPoints: 'full',
76-
closeable: true,
76+
hideCloseButton: false,
7777
onBack: undefined,
7878
onClose: undefined,
7979
enableHandlePanningGesture: true,
@@ -118,7 +118,7 @@ export const Base: Story = {
118118
export const TitleExpanded: Story = {
119119
args: {
120120
snapPoints: 'full',
121-
closeable: true,
121+
hideCloseButton: false,
122122
enableHandlePanningGesture: true,
123123
enablePanDownToClose: true,
124124
enableBlurKeyboardOnGesture: true,
@@ -161,7 +161,7 @@ export const TitleExpanded: Story = {
161161

162162
export const DynamicSizing: Story = {
163163
args: {
164-
closeable: true,
164+
hideCloseButton: false,
165165
enableHandlePanningGesture: true,
166166
enablePanDownToClose: true,
167167
enableBlurKeyboardOnGesture: true,
@@ -202,7 +202,7 @@ export const DynamicSizing: Story = {
202202
export const DynamicSizingAndMaxSize: Story = {
203203
args: {
204204
snapPoints: undefined,
205-
closeable: true,
205+
hideCloseButton: false,
206206
enableHandlePanningGesture: true,
207207
enablePanDownToClose: true,
208208
enableBlurKeyboardOnGesture: true,
@@ -242,10 +242,10 @@ export const DynamicSizingAndMaxSize: Story = {
242242
},
243243
};
244244

245-
export const NonCloseable: Story = {
245+
export const HiddenCloseButton: Story = {
246246
args: {
247247
snapPoints: 'full',
248-
closeable: false,
248+
hideCloseButton: false,
249249
onClose: undefined,
250250
enableHandlePanningGesture: true,
251251
enablePanDownToClose: false,
@@ -265,7 +265,7 @@ export const NonCloseable: Story = {
265265
<BottomSheet {...args} ref={bottomSheetRef}>
266266
<BottomSheetView>
267267
<BottomSheetHeader
268-
title='Non-Closeable'
268+
title='Hidden Close Button'
269269
appearance='compact'
270270
description='This bottom sheet cannot be closed by dragging or button'
271271
/>
@@ -288,7 +288,7 @@ export const NonCloseable: Story = {
288288
export const ScrollView: Story = {
289289
args: {
290290
snapPoints: 'full',
291-
closeable: true,
291+
hideCloseButton: false,
292292
enableHandlePanningGesture: true,
293293
enablePanDownToClose: true,
294294
enableBlurKeyboardOnGesture: true,
@@ -331,7 +331,7 @@ export const ScrollView: Story = {
331331
export const VirtualList: Story = {
332332
args: {
333333
snapPoints: 'full',
334-
closeable: true,
334+
hideCloseButton: false,
335335
enableHandlePanningGesture: true,
336336
enablePanDownToClose: true,
337337
enableBlurKeyboardOnGesture: true,
@@ -392,7 +392,7 @@ export const VirtualList: Story = {
392392
export const VirtualizedList: Story = {
393393
args: {
394394
snapPoints: 'full',
395-
closeable: true,
395+
hideCloseButton: false,
396396
enableHandlePanningGesture: true,
397397
enablePanDownToClose: true,
398398
enableBlurKeyboardOnGesture: true,

libs/ui-rnative/src/lib/Components/BottomSheet/BottomSheet.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('BottomSheet', () => {
9696
});
9797

9898
describe('snap points', () => {
99-
it('uses default snapPoints "half" when not specified', () => {
99+
it('uses default snapPoints "medium" when not specified', () => {
100100
const { BottomSheet } = require('./BottomSheet');
101101
const { getByTestId } = render(
102102
<BottomSheet testID='bottom-sheet'>
@@ -123,7 +123,7 @@ describe('BottomSheet', () => {
123123
it('renders with snapPoints preset "quarter"', () => {
124124
const { BottomSheet } = require('./BottomSheet');
125125
const { getByTestId } = render(
126-
<BottomSheet snapPoints='quarter' testID='bottom-sheet'>
126+
<BottomSheet snapPoints='small' testID='bottom-sheet'>
127127
<Text>Content</Text>
128128
</BottomSheet>,
129129
);
@@ -239,10 +239,10 @@ describe('BottomSheet', () => {
239239
expect(getByText('Content')).toBeTruthy();
240240
});
241241

242-
it('provides context with closeable prop', () => {
242+
it('provides context with hideCloseButton prop', () => {
243243
const { BottomSheet } = require('./BottomSheet');
244244
const { getByText } = render(
245-
<BottomSheet closeable testID='bottom-sheet'>
245+
<BottomSheet hideCloseButton testID='bottom-sheet'>
246246
<Text>Content</Text>
247247
</BottomSheet>,
248248
);
@@ -251,11 +251,11 @@ describe('BottomSheet', () => {
251251
expect(getByText('Content')).toBeTruthy();
252252
});
253253

254-
it('provides context with both onBack and closeable', () => {
254+
it('provides context with both onBack and hideCloseButton', () => {
255255
const { BottomSheet } = require('./BottomSheet');
256256
const onBack = jest.fn();
257257
const { getByText } = render(
258-
<BottomSheet onBack={onBack} closeable testID='bottom-sheet'>
258+
<BottomSheet onBack={onBack} hideCloseButton testID='bottom-sheet'>
259259
<Text>Content</Text>
260260
</BottomSheet>,
261261
);

libs/ui-rnative/src/lib/Components/BottomSheet/BottomSheet.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const StyledGorghomBottomSheet = cssInterop(GorghomBottomSheet, {
1414

1515
const SNAP_POINTS = {
1616
full: ['95%'],
17-
half: ['50%'],
18-
quarter: ['25%'],
17+
medium: ['50%'],
18+
small: ['25%'],
1919
};
2020

2121
const bottomSheetVariants = {
@@ -31,7 +31,7 @@ const bottomSheetVariants = {
3131
};
3232

3333
const [BottomSheetProvider, useBottomSheetContext] =
34-
createSafeContext<Pick<BottomSheetProps, 'onBack' | 'closeable'>>(
34+
createSafeContext<Pick<BottomSheetProps, 'onBack' | 'hideCloseButton'>>(
3535
'BottomSheet',
3636
);
3737

@@ -45,8 +45,8 @@ const BottomSheet = forwardRef<
4545
onClose,
4646
onBack,
4747
onAnimate,
48-
closeable,
4948
children,
49+
hideCloseButton = false,
5050
enablePanDownToClose = true,
5151
enableDynamicSizing = false,
5252
enableBlurKeyboardOnGesture = true,
@@ -57,7 +57,7 @@ const BottomSheet = forwardRef<
5757
showBackdropPress = false,
5858
onBackdropPress,
5959
onChange,
60-
snapPoints = 'half',
60+
snapPoints = 'medium x',
6161
...props
6262
},
6363
ref,
@@ -100,14 +100,12 @@ const BottomSheet = forwardRef<
100100

101101
const handleChange: BottomSheetProps['onChange'] = useCallback(
102102
(index: number, position: number, type: SNAP_POINT_TYPE) => {
103-
console.log('onchange');
104103
if (index === -1 && onClose) {
105104
onClose();
106105
}
107106
if (index === 0 && onOpen) {
108107
onOpen();
109108
}
110-
setIsOpen(index === 0);
111109
onChange?.(index, position, type);
112110
},
113111
[onClose, onOpen, onChange],
@@ -129,15 +127,8 @@ const BottomSheet = forwardRef<
129127
[onAnimate],
130128
);
131129

132-
console.log({ isOpen });
133-
134-
console.log({ a: innerRef.current });
135-
136-
// renders
137130
return (
138-
<BottomSheetProvider
139-
value={{ onBack, closeable: Boolean(onClose || closeable) }}
140-
>
131+
<BottomSheetProvider value={{ onBack, hideCloseButton }}>
141132
<StyledGorghomBottomSheet
142133
{...props}
143134
ref={mergedRefs}

libs/ui-rnative/src/lib/Components/BottomSheet/BottomSheetHeader.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useBottomSheetContext } from './BottomSheet';
99
import { BottomSheetHeaderProps } from './types';
1010

1111
const bottomSheetHeaderVariants = {
12-
root: cva('z-dialog-content bg-canvas-sheet sticky top-0 pb-12', {
12+
root: cva('sticky top-0 z-dialog-content bg-canvas-sheet pb-12', {
1313
variants: {
1414
spacing: {
1515
true: 'px-16',
@@ -40,7 +40,7 @@ const bottomSheetHeaderVariants = {
4040
title: cva('text-base', {
4141
variants: {
4242
appearance: {
43-
compact: 'heading-4-semi-bold text-center',
43+
compact: 'text-center heading-4-semi-bold',
4444
expanded: 'heading-2-semi-bold',
4545
},
4646
},
@@ -64,7 +64,7 @@ export const BottomSheetHeader: FC<BottomSheetHeaderProps> = ({
6464
...props
6565
}) => {
6666
const { close } = useBottomSheet();
67-
const { onBack, closeable } = useBottomSheetContext({
67+
const { onBack, hideCloseButton } = useBottomSheetContext({
6868
consumerName: 'BottomSheetHeader',
6969
contextRequired: true,
7070
});
@@ -74,9 +74,9 @@ export const BottomSheetHeader: FC<BottomSheetHeaderProps> = ({
7474
}, [close]);
7575

7676
const hasTitleSection = Boolean(title || description);
77-
const hasIcons = Boolean(onBack || closeable);
77+
const hasIcons = Boolean(onBack || !hideCloseButton);
7878

79-
if (!title && !description && !onBack && !closeable) {
79+
if (!title && !description && !onBack && hideCloseButton) {
8080
return null;
8181
}
8282

@@ -106,23 +106,23 @@ export const BottomSheetHeader: FC<BottomSheetHeaderProps> = ({
106106
hidden: !hasIcons && appearance !== 'compact',
107107
})}
108108
>
109-
<View className='size-44'>
109+
<View className='size-32'>
110110
{onBack && (
111111
<IconButton
112112
accessibilityLabel='Go back'
113-
size='sm'
113+
size='xs'
114114
onPress={onBack}
115115
icon={ArrowLeft}
116116
appearance='transparent'
117117
/>
118118
)}
119119
</View>
120120
{appearance === 'compact' && titleComponent}
121-
<View className='size-44'>
122-
{closeable && (
121+
<View className='size-32'>
122+
{!hideCloseButton && (
123123
<IconButton
124124
accessibilityLabel='Close'
125-
size='sm'
125+
size='xs'
126126
onPress={handleClose}
127127
icon={Close}
128128
appearance='transparent'

libs/ui-rnative/src/lib/Components/BottomSheet/types.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export type BottomSheetProps = PropsWithChildren & {
2222
testID?: string;
2323
/**
2424
* The snap points represent allowed heights of the bottom sheet.
25-
* You can use presets like 'full', 'half', 'quarter' or define your own snap points in % (string) or pixel (number).
25+
* You can use presets like 'full', 'medium', 'small' or define your own snap points in % (string) or pixel (number).
2626
* If you want to use dynamic sizing, you should not define snapPoints.
2727
* @default 'full'
2828
*/
29-
snapPoints?: 'full' | 'half' | 'quarter' | string[] | number[];
29+
snapPoints?: 'full' | 'medium' | 'small' | string[] | number[];
3030
/**
3131
* If true, the bottom sheet will be resized to fit the content.
3232
* You should not define snapPoints when enableDynamicSizing is true.
@@ -55,19 +55,17 @@ export type BottomSheetProps = PropsWithChildren & {
5555
*/
5656
onBack?: () => void;
5757
/**
58-
* If true, the close button will be displayed.
59-
* This property should be used when no callback is required for the close action.
58+
* If true, the close button will be hidden.
6059
* @default false
6160
*/
62-
closeable?: boolean;
61+
hideCloseButton?: boolean;
6362
/**
64-
* If true, the close button will be displayed
65-
* This property should be used when a callback function to handle the close event is required.
63+
* Callback function to handle the close event.
6664
* @default undefined
6765
*/
6866
onClose?: () => void;
6967
/**
70-
* The callback function to handle the open event.
68+
* Callback function to handle the open event.
7169
* @default undefined
7270
*/
7371
onOpen?: () => void;

0 commit comments

Comments
 (0)