@startupjs-ui/drawer-sidebar 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [0.1.3](https://github.com/startupjs/startupjs-ui/compare/v0.1.2...v0.1.3) (2025-12-29)
7
+
8
+ **Note:** Version bump only for package @startupjs-ui/drawer-sidebar
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.1.2](https://github.com/startupjs/startupjs-ui/compare/v0.1.1...v0.1.2) (2025-12-29)
15
+
16
+
17
+ ### Features
18
+
19
+ * add mdx and docs packages. Refactor docs to get rid of any @startupjs/ui usage and use startupjs-ui instead ([703c926](https://github.com/startupjs/startupjs-ui/commit/703c92636efb0421ffd11783f692fc892b74018f))
20
+ * **drawer-sidebar:** refactor DrawerSidebar component ([f323bdd](https://github.com/startupjs/startupjs-ui/commit/f323bdddab7c8dabecf224a5b35c1a75a483556f))
package/README.mdx ADDED
@@ -0,0 +1,163 @@
1
+ import DrawerSidebar, { _PropsJsonSchema as DrawerSidebarPropsJsonSchema } from './index'
2
+ import Br from '@startupjs-ui/br'
3
+ import Button from '@startupjs-ui/button'
4
+ import Content from '@startupjs-ui/content'
5
+ import Div from '@startupjs-ui/div'
6
+ import Menu from '@startupjs-ui/menu'
7
+ import Span from '@startupjs-ui/span'
8
+ import { $ } from 'startupjs'
9
+ import { Sandbox } from '@startupjs-ui/docs'
10
+ import './index.mdx.cssx.styl'
11
+
12
+ # DrawerSidebar
13
+
14
+ Drawer is typically used for nagivation. It initially not visible on the screen, but it can be pulled in from the edge of the window.
15
+
16
+ ```jsx
17
+ import { DrawerSidebar } from 'startupjs-ui'
18
+ ```
19
+
20
+ ## Simple example
21
+
22
+ ```jsx example
23
+ const $open = $()
24
+ return (
25
+ <Div style={{overflow: 'hidden'}}>
26
+ <DrawerSidebar
27
+ $open={$open}
28
+ renderContent={() => (
29
+ <Span>
30
+ DrawerSidebar
31
+ </Span>)
32
+ }
33
+ >
34
+ <Button onPress={() => $open.set(true)}>Open</Button>
35
+ </DrawerSidebar>
36
+ </Div>
37
+ )
38
+ ```
39
+
40
+ ## Position
41
+
42
+ The `position` property specifies the side of the window from which the drawer will slide in. Possible values of `position` property are `left` (default) and `right`.
43
+
44
+ ```jsx example noscroll
45
+ const $open = $()
46
+ return (
47
+ <Div style={{overflow: 'hidden'}}>
48
+ <DrawerSidebar
49
+ $open={$open}
50
+ position='right'
51
+ renderContent={() => (
52
+ <Menu>
53
+ <Menu.Item>Nav-1</Menu.Item>
54
+ <Menu.Item>Nav-2</Menu.Item>
55
+ <Menu.Item>Nav-3</Menu.Item>
56
+ <Menu.Item>Nav-4</Menu.Item>
57
+ </Menu>
58
+ )}
59
+ >
60
+ <Content
61
+ padding
62
+ width='full'
63
+ style={{ backgroundColor: 'white' }}
64
+ >
65
+ <Div row>
66
+ <Button onPress={() => $open.set(true)}>Open</Button>
67
+ </Div>
68
+ <Br />
69
+ <Span>
70
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Rhoncus dolor purus non enim praesent elementum facilisis leo vel. Risus at ultrices mi tempus imperdiet. Semper risus in hendrerit gravida rutrum quisque non tellus.
71
+ </Span>
72
+ </Content>
73
+ </DrawerSidebar>
74
+ </Div>
75
+ )
76
+ ```
77
+
78
+ ## Lazy rendering
79
+
80
+ By default the drawer content are not destroyed when it is closed. To change this behavior pass `lazy=true`.
81
+
82
+ ```jsx example
83
+ const $open = $()
84
+ return (
85
+ <Div style={{overflow: 'hidden'}}>
86
+ <DrawerSidebar
87
+ $open={$open}
88
+ renderContent={() => (
89
+ <Span>
90
+ Lazy DrawerSidebar
91
+ </Span>)
92
+ }
93
+ lazy
94
+ >
95
+ <Button onPress={() => $open.set(true)}>Open</Button>
96
+ </DrawerSidebar>
97
+ </Div>
98
+ )
99
+ ```
100
+
101
+ ## Complex example
102
+
103
+ ```jsx example noscroll
104
+ const $open = $()
105
+ return (
106
+ <Div style={{overflow: 'hidden'}}>
107
+ <DrawerSidebar
108
+ $open={$open}
109
+ renderContent={() => (
110
+ <Menu>
111
+ <Menu.Item>Nav-1</Menu.Item>
112
+ <Menu.Item>Nav-2</Menu.Item>
113
+ <Menu.Item>Nav-3</Menu.Item>
114
+ <Menu.Item>Nav-4</Menu.Item>
115
+ </Menu>
116
+ )}
117
+ >
118
+ <Content
119
+ padding
120
+ width='full'
121
+ style={{ backgroundColor: 'white' }}
122
+ >
123
+ <Div row>
124
+ <Button onPress={() => $open.set(true)}>Open</Button>
125
+ </Div>
126
+ <Br />
127
+ <Span>
128
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Rhoncus dolor purus non enim praesent elementum facilisis leo vel. Risus at ultrices mi tempus imperdiet. Semper risus in hendrerit gravida rutrum quisque non tellus.
129
+ </Span>
130
+ </Content>
131
+ </DrawerSidebar>
132
+ </Div>
133
+ )
134
+ ```
135
+
136
+ ## Sandbox
137
+
138
+ <Sandbox
139
+ Component={DrawerSidebar}
140
+ props={{
141
+ $open: $.session.Sandbox.DrawerSidebar,
142
+ renderContent: () => (
143
+ <Div styleName='sidebar'>
144
+ <Span>Sidebar content</Span>
145
+ </Div>
146
+ ),
147
+ children: (
148
+ <Div styleName='content'>
149
+ <Button
150
+ onPress={()=> {
151
+ const value = $.session.Sandbox.DrawerSidebar.get()
152
+ $.session.Sandbox.DrawerSidebar.set(!value)
153
+ }}
154
+ >Open</Button>
155
+ <Br />
156
+ <Span>Children content</Span>
157
+ </Div>
158
+ )
159
+ }}
160
+ rendererStyleName='renderer'
161
+ block
162
+ propsJsonSchema={DrawerSidebarPropsJsonSchema}
163
+ />
package/index.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /* eslint-disable */
2
+ // DO NOT MODIFY THIS FILE - IT IS AUTOMATICALLY GENERATED ON COMMITS.
3
+
4
+ import React, { type ReactNode } from 'react';
5
+ import { type StyleProp, type ViewStyle } from 'react-native';
6
+ export declare const _PropsJsonSchema: {};
7
+ export interface DrawerSidebarProps {
8
+ /** Custom styles applied to the root DrawerLayout */
9
+ style?: StyleProp<ViewStyle>;
10
+ /** Content rendered inside the main area */
11
+ children?: ReactNode;
12
+ /** Model controlling drawer open state */
13
+ $open?: any;
14
+ /** Drawer position relative to the screen @default 'left' */
15
+ position?: 'left' | 'right';
16
+ /** Render drawer content only when open @default false */
17
+ lazy?: boolean;
18
+ /** Disable drawer interactions @default false */
19
+ disabled?: boolean;
20
+ /** Drawer width in density-independent pixels @default 264 */
21
+ width?: number;
22
+ /** Renderer for drawer content */
23
+ renderContent?: () => ReactNode;
24
+ }
25
+ declare const _default: React.ComponentType<DrawerSidebarProps>;
26
+ export default _default;
@@ -0,0 +1,9 @@
1
+ .sidebar
2
+ padding 2u
3
+
4
+ .content
5
+ padding 2u
6
+ height 20u
7
+
8
+ .renderer
9
+ overflow hidden
package/index.tsx ADDED
@@ -0,0 +1,102 @@
1
+ import React, { useRef, type ReactNode } from 'react'
2
+ import { ScrollView, StyleSheet, type StyleProp, type ViewStyle } from 'react-native'
3
+ import DrawerLayoutModule from 'react-native-drawer-layout-polyfill'
4
+ import { pug, observer, $, useDidUpdate } from 'startupjs'
5
+ import { themed, useColors } from '@startupjs-ui/core'
6
+
7
+ const DrawerLayout = DrawerLayoutModule.default || DrawerLayoutModule
8
+ if (!DrawerLayout) throw Error("> Can't load DrawerLayout module. Issues with bundling.")
9
+
10
+ let isEffectRunning: boolean | undefined
11
+
12
+ export const _PropsJsonSchema = {/* DrawerSidebarProps */}
13
+
14
+ export interface DrawerSidebarProps {
15
+ /** Custom styles applied to the root DrawerLayout */
16
+ style?: StyleProp<ViewStyle>
17
+ /** Content rendered inside the main area */
18
+ children?: ReactNode
19
+ /** Model controlling drawer open state */
20
+ $open?: any
21
+ /** Drawer position relative to the screen @default 'left' */
22
+ position?: 'left' | 'right'
23
+ /** Render drawer content only when open @default false */
24
+ lazy?: boolean
25
+ /** Disable drawer interactions @default false */
26
+ disabled?: boolean
27
+ /** Drawer width in density-independent pixels @default 264 */
28
+ width?: number
29
+ /** Renderer for drawer content */
30
+ renderContent?: () => ReactNode
31
+ }
32
+
33
+ function DrawerSidebar ({
34
+ style = [],
35
+ children,
36
+ $open,
37
+ position = 'left',
38
+ lazy = false,
39
+ disabled = false,
40
+ width = 264,
41
+ renderContent,
42
+ ...props
43
+ }: DrawerSidebarProps): ReactNode {
44
+ const getColor = useColors()
45
+
46
+ if (!$open) $open = $()
47
+
48
+ const flattenedStyle = StyleSheet.flatten(style) || {}
49
+ const { backgroundColor = getColor('bg-main-strong'), ...restStyle } =
50
+ flattenedStyle as Record<string, any>
51
+
52
+ const open = $open.get()
53
+
54
+ const drawerRef = useRef<any>(null)
55
+
56
+ useDidUpdate(() => {
57
+ if (disabled) return
58
+ const drawer = drawerRef.current
59
+
60
+ isEffectRunning = true
61
+
62
+ if (open) {
63
+ drawer.openDrawer()
64
+ } else {
65
+ drawer.closeDrawer()
66
+ }
67
+ }, [!!open])
68
+
69
+ const renderNavigationView = (): ReactNode => {
70
+ const render = lazy ? open : true
71
+ if (!render) return null
72
+ return pug`
73
+ ScrollView(contentContainerStyle={flex: 1})
74
+ = renderContent && renderContent()
75
+ `
76
+ }
77
+
78
+ // drawer callback's are scheduled and not called synchronously
79
+ // and when the open state changes several times in a short period of time
80
+ // these scheduled callback's can create an infinite loop
81
+ function onDrawerCallback (openState: boolean) {
82
+ if (typeof isEffectRunning === 'undefined') $open.set(openState)
83
+ isEffectRunning = undefined
84
+ }
85
+
86
+ return pug`
87
+ DrawerLayout.root(
88
+ style=restStyle
89
+ drawerPosition=position
90
+ drawerWidth=width
91
+ drawerBackgroundColor=backgroundColor
92
+ ref=drawerRef
93
+ renderNavigationView=renderNavigationView
94
+ onDrawerClose=() => onDrawerCallback(false)
95
+ onDrawerOpen=() => onDrawerCallback(true)
96
+ drawerLockMode=disabled ? 'locked-closed' : undefined
97
+ ...props
98
+ )= children
99
+ `
100
+ }
101
+
102
+ export default observer(themed('DrawerSidebar', DrawerSidebar))
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@startupjs-ui/drawer-sidebar",
3
+ "version": "0.1.3",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "main": "index.tsx",
8
+ "types": "index.d.ts",
9
+ "type": "module",
10
+ "dependencies": {
11
+ "@startupjs-ui/core": "^0.1.3",
12
+ "react-native-drawer-layout-polyfill": "^2.0.0"
13
+ },
14
+ "peerDependencies": {
15
+ "react": "*",
16
+ "react-native": "*",
17
+ "startupjs": "*"
18
+ },
19
+ "gitHead": "fd964ebc3892d3dd0a6c85438c0af619cc50c3f0"
20
+ }
@@ -0,0 +1,4 @@
1
+ declare module 'react-native-drawer-layout-polyfill' {
2
+ const DrawerLayout: any
3
+ export default DrawerLayout
4
+ }