@startupjs-ui/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,21 @@
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/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))
21
+ * **sidebar:** refactor Sidebar component ([8663a5e](https://github.com/startupjs/startupjs-ui/commit/8663a5eb3a75eca1e895d0e434a3d78ecd37eccb))
package/README.mdx ADDED
@@ -0,0 +1,189 @@
1
+ import Sidebar, { _PropsJsonSchema as SidebarPropsJsonSchema } from './index'
2
+ import Div from '@startupjs-ui/div'
3
+ import Menu from '@startupjs-ui/menu'
4
+ import Button from '@startupjs-ui/button'
5
+ import Br from '@startupjs-ui/br'
6
+ import Content from '@startupjs-ui/content'
7
+ import Span from '@startupjs-ui/span'
8
+ import { $, pug } from 'startupjs'
9
+ import { useMedia } from '@startupjs-ui/core'
10
+ import { Sandbox } from '@startupjs-ui/docs'
11
+ import './index.mdx.cssx.styl'
12
+
13
+ # Sidebar
14
+
15
+ Sidebar is typically used for nagivation. It initially not visible on the screen.
16
+
17
+ ```jsx
18
+ import { Sidebar } from 'startupjs-ui'
19
+ ```
20
+
21
+ ## Simple example
22
+
23
+ ```jsx example
24
+ const media = useMedia()
25
+ const $open = $()
26
+
27
+ return (
28
+ <Sidebar
29
+ $open={$open}
30
+ width={media.tablet ? 264 : 120}
31
+ renderContent={() => (
32
+ <Span>
33
+ Sidebar
34
+ </Span>
35
+ )}
36
+ >
37
+ <Button onPress={() => $open.set(!$open.get())}>
38
+ Toggle sidebar
39
+ </Button>
40
+ </Sidebar>
41
+ )
42
+ ```
43
+
44
+ ## Position
45
+
46
+ The `position` property specifies the side of the window from which the sidebar will show. Possible values of `position` property are `left` (default) and `right`.
47
+
48
+ ```jsx example noscroll
49
+ const media = useMedia()
50
+ const $open = $()
51
+
52
+ return (
53
+ <Sidebar
54
+ $open={$open}
55
+ width={media.tablet ? 264 : 120}
56
+ position='right'
57
+ renderContent={() => (
58
+ <Menu>
59
+ <Menu.Item onPress={() => null}>Nav-1</Menu.Item>
60
+ <Menu.Item onPress={() => null}>Nav-2</Menu.Item>
61
+ <Menu.Item onPress={() => null}>Nav-3</Menu.Item>
62
+ <Menu.Item onPress={() => null}>Nav-4</Menu.Item>
63
+ <Menu.Item onPress={() => null}>Nav-5</Menu.Item>
64
+ <Menu.Item onPress={() => null}>Nav-6</Menu.Item>
65
+ </Menu>
66
+ )}
67
+ >
68
+ <Content
69
+ padding
70
+ width='full'
71
+ style={{
72
+ backgroundColor: 'white'
73
+ }}
74
+ >
75
+ <Div row>
76
+ <Button
77
+ variant='flat'
78
+ onPress={() => { $open.set(!$open.get()) }}
79
+ >
80
+ Toggle right sidebar
81
+ </Button>
82
+ </Div>
83
+ <Br />
84
+ <Span>
85
+ 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.
86
+ </Span>
87
+ </Content>
88
+ </Sidebar>
89
+ )
90
+ ```
91
+
92
+ ## Lazy rendering
93
+
94
+ By default the sidebar content are not destroyed when it is closed. To change this behavior pass `lazy=true`.
95
+
96
+ ```jsx example
97
+ const media = useMedia()
98
+ const $open = $()
99
+
100
+ return (
101
+ <Sidebar
102
+ $open={$open}
103
+ width={media.tablet ? 264 : 120}
104
+ renderContent={() => (
105
+ <Span>
106
+ Lazy sidebar
107
+ </Span>
108
+ )}
109
+ lazy
110
+ >
111
+ <Button onPress={() => $open.set(!$open.get())}>
112
+ Toggle sidebar
113
+ </Button>
114
+ </Sidebar>
115
+ )
116
+ ```
117
+
118
+ ## Complex example
119
+
120
+ ```jsx example noscroll
121
+ const media = useMedia()
122
+ const $open = $()
123
+
124
+ return (
125
+ <Sidebar
126
+ $open={$open}
127
+ width={media.tablet ? 264 : 120}
128
+ renderContent={() => (
129
+ <Menu>
130
+ <Menu.Item onPress={() => null}>Nav-1</Menu.Item>
131
+ <Menu.Item onPress={() => null}>Nav-2</Menu.Item>
132
+ <Menu.Item onPress={() => null}>Nav-3</Menu.Item>
133
+ <Menu.Item onPress={() => null}>Nav-4</Menu.Item>
134
+ <Menu.Item onPress={() => null}>Nav-5</Menu.Item>
135
+ <Menu.Item onPress={() => null}>Nav-6</Menu.Item>
136
+ </Menu>
137
+ )}
138
+ >
139
+ <Content
140
+ padding
141
+ width='full'
142
+ style={{
143
+ backgroundColor: 'white'
144
+ }}
145
+ >
146
+ <Div row>
147
+ <Button variant='flat' onPress={() => $open.set(!$open.get())}>
148
+ Toggle sidebar
149
+ </Button>
150
+ </Div>
151
+ <Br />
152
+ <Span>
153
+ 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.
154
+ </Span>
155
+ </Content>
156
+ </Sidebar>
157
+ )
158
+ ```
159
+
160
+ ## Sandbox
161
+
162
+ <Sandbox Component={Sidebar}
163
+ props={{
164
+ // TODO: $open is not working here probably because Sandbox doesn't accept model props correctly
165
+ $open: $.session.Sandbox.Sidebar,
166
+ renderContent: () => {
167
+ return pug`
168
+ Div.sidebar
169
+ Span Sidebar content
170
+ `
171
+ },
172
+ children: (
173
+ <Div styleName='content'>
174
+ <Button
175
+ styleName='button'
176
+ onPress={() => {
177
+ console.log('Toggle sidebar')
178
+ const value = $.session.Sandbox.Sidebar.get()
179
+ $.session.Sandbox.Sidebar.set(!value)
180
+ }}
181
+ >Toggle</Button>
182
+ <Br />
183
+ <Span>Children content</Span>
184
+ </Div>
185
+ )
186
+ }}
187
+ propsJsonSchema={SidebarPropsJsonSchema}
188
+ block
189
+ />
@@ -0,0 +1,18 @@
1
+ .root
2
+ height 100%
3
+ flex-direction row
4
+ flex-shrink 1
5
+
6
+ &.right
7
+ flex-direction row-reverse
8
+
9
+ .sidebar
10
+ flex-direction column
11
+ display none
12
+ flex-grow 0
13
+ &.open
14
+ display flex
15
+
16
+ .main
17
+ flex-direction column
18
+ flex 1
package/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ /* eslint-disable */
2
+ // DO NOT MODIFY THIS FILE - IT IS AUTOMATICALLY GENERATED ON COMMITS.
3
+
4
+ import { type ReactNode } from 'react';
5
+ import { type StyleProp, type ViewStyle } from 'react-native';
6
+ import './index.cssx.styl';
7
+ declare const _default: import("react").ComponentType<SidebarProps>;
8
+ export default _default;
9
+ export declare const _PropsJsonSchema: {};
10
+ export interface SidebarProps {
11
+ /** Custom styles applied to the root view */
12
+ style?: StyleProp<ViewStyle>;
13
+ /** Custom styles applied to the sidebar container */
14
+ sidebarStyle?: StyleProp<ViewStyle>;
15
+ /** Custom styles applied to the main content container */
16
+ contentStyle?: StyleProp<ViewStyle>;
17
+ /** Content rendered inside the main area */
18
+ children?: ReactNode;
19
+ /** Model controlling sidebar open state */
20
+ $open?: any;
21
+ /** Sidebar position relative to the content @default 'left' */
22
+ position?: 'left' | 'right';
23
+ /** Disable sidebar toggling @default false */
24
+ disabled?: boolean;
25
+ /** Sidebar width in density-independent pixels @default 264 */
26
+ width?: number;
27
+ /** Render sidebar content only when open @default false */
28
+ lazy?: boolean;
29
+ /** Custom renderer for sidebar content */
30
+ renderContent?: () => ReactNode;
31
+ }
@@ -0,0 +1,11 @@
1
+ .sidebar
2
+ padding 2u
3
+ height 20u
4
+
5
+ .content
6
+ padding 2u
7
+ height 20u
8
+ background-color var(--color-bg-main)
9
+
10
+ .button
11
+ width 10u
package/index.tsx ADDED
@@ -0,0 +1,69 @@
1
+ import { type ReactNode } from 'react'
2
+ import { ScrollView, View, StyleSheet, type StyleProp, type ViewStyle } from 'react-native'
3
+ import { pug, observer } from 'startupjs'
4
+ import { themed, useColors } from '@startupjs-ui/core'
5
+ import Div from '@startupjs-ui/div'
6
+ import './index.cssx.styl'
7
+
8
+ export default observer(themed('Sidebar', Sidebar))
9
+
10
+ export const _PropsJsonSchema = {/* SidebarProps */}
11
+
12
+ export interface SidebarProps {
13
+ /** Custom styles applied to the root view */
14
+ style?: StyleProp<ViewStyle>
15
+ /** Custom styles applied to the sidebar container */
16
+ sidebarStyle?: StyleProp<ViewStyle>
17
+ /** Custom styles applied to the main content container */
18
+ contentStyle?: StyleProp<ViewStyle>
19
+ /** Content rendered inside the main area */
20
+ children?: ReactNode
21
+ /** Model controlling sidebar open state */
22
+ $open?: any
23
+ /** Sidebar position relative to the content @default 'left' */
24
+ position?: 'left' | 'right'
25
+ /** Disable sidebar toggling @default false */
26
+ disabled?: boolean
27
+ /** Sidebar width in density-independent pixels @default 264 */
28
+ width?: number
29
+ /** Render sidebar content only when open @default false */
30
+ lazy?: boolean
31
+ /** Custom renderer for sidebar content */
32
+ renderContent?: () => ReactNode
33
+ }
34
+
35
+ function Sidebar ({
36
+ style = [],
37
+ sidebarStyle,
38
+ contentStyle,
39
+ children,
40
+ $open,
41
+ position = 'left',
42
+ disabled = false,
43
+ width = 264,
44
+ lazy = false,
45
+ renderContent
46
+ }: SidebarProps): ReactNode {
47
+ const getColor = useColors()
48
+
49
+ const flattenedStyle = StyleSheet.flatten(style) || {}
50
+ const { backgroundColor = getColor('bg-main-strong'), ...restStyle } = flattenedStyle
51
+
52
+ const open = disabled ? false : $open?.get()
53
+
54
+ function renderSidebarContent (): ReactNode {
55
+ const render = lazy ? open : true
56
+ if (!render) return null
57
+ return renderContent && renderContent()
58
+ }
59
+
60
+ return pug`
61
+ Div.root(style=restStyle styleName=[position])
62
+ ScrollView.sidebar(
63
+ contentContainerStyle=[{ flex: 1 }, sidebarStyle]
64
+ styleName={open}
65
+ style={ width, backgroundColor }
66
+ )= renderSidebarContent()
67
+ View.main(style=contentStyle)= children
68
+ `
69
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@startupjs-ui/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
+ "@startupjs-ui/div": "^0.1.3"
13
+ },
14
+ "peerDependencies": {
15
+ "react": "*",
16
+ "react-native": "*",
17
+ "startupjs": "*"
18
+ },
19
+ "gitHead": "fd964ebc3892d3dd0a6c85438c0af619cc50c3f0"
20
+ }