b44ui 0.0.12 → 0.0.13
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/index.tsx +33 -32
- package/package.json +1 -1
- package/styles.css +10 -11
package/index.tsx
CHANGED
|
@@ -42,12 +42,13 @@ export type DProps = {
|
|
|
42
42
|
gap?: number
|
|
43
43
|
p?: number
|
|
44
44
|
wd?: number
|
|
45
|
+
ht?: number
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
const dStyle = ({ gap, p, wd, style }: DProps): React.CSSProperties | undefined => {
|
|
48
|
+
const dStyle = ({ gap, p, wd, ht, style }: DProps): React.CSSProperties | undefined => {
|
|
48
49
|
const g = sc(gap), pd = sc(p)
|
|
49
|
-
if (!g && !pd && wd === undefined && !style) return undefined
|
|
50
|
-
return { ...(g !== undefined && { gap: g }), ...(pd !== undefined && { padding: pd }), ...(wd !== undefined && { width: `${wd * 100}%` }), ...style }
|
|
50
|
+
if (!g && !pd && wd === undefined && ht === undefined && !style) return undefined
|
|
51
|
+
return { ...(g !== undefined && { gap: g }), ...(pd !== undefined && { padding: pd }), ...(wd !== undefined && { width: `${wd * 100}%` }), ...(ht !== undefined && { height: `${ht * 100}%` }), ...style }
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
export const D = (props: DProps) =>
|
|
@@ -63,13 +64,13 @@ export const App = (props: DProps & { center?: boolean, width?: number }) => {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
export const Centered = (props: DProps & { width?: number }) => {
|
|
66
|
-
const { children, grow, gap, p, width = 700 } = props
|
|
67
|
-
return <D cn={CN("mx-auto max-w-full px-6", rcn(props))} grow={grow} gap={gap} p={p} style={{ width }}>{children}</D>
|
|
67
|
+
const { children, grow, gap, p, wd, ht, width = 700 } = props
|
|
68
|
+
return <D cn={CN("mx-auto max-w-full px-6", rcn(props))} grow={grow} gap={gap} p={p} wd={wd} ht={ht} style={{ width }}>{children}</D>
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
export const TabList = (props: DProps) => {
|
|
71
|
-
const { children, grow, gap, p } = props
|
|
72
|
-
return <D cn={CN("flex items-end gap-4", rcn(props))} grow={grow} gap={gap} p={p}>{children}</D>
|
|
72
|
+
const { children, grow, gap, p, wd, ht } = props
|
|
73
|
+
return <D cn={CN("flex items-end gap-4", rcn(props))} grow={grow} gap={gap} p={p} wd={wd} ht={ht}>{children}</D>
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
export const Tab = ({ title, active, click, grow, gap, p, ...rest }: DProps & { title: ReactNode, active?: boolean, click?: () => void } & React.ButtonHTMLAttributes<HTMLButtonElement>) => {
|
|
@@ -85,35 +86,35 @@ export const Tab = ({ title, active, click, grow, gap, p, ...rest }: DProps & {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
export const Block = (props: DProps & { label?: ReactNode, row?: boolean, dashed?: boolean }) => {
|
|
88
|
-
const { label, children, row, dashed, grow, gap, p } = props
|
|
89
|
-
return <D cn={CN("rounded flex flex-col items-center", dashed && "border border-dashed border-zinc-700", rcn(props))} grow={grow} gap={gap ?? 4} p={p ?? 4}>
|
|
89
|
+
const { label, children, row, dashed, grow, gap, p, wd, ht } = props
|
|
90
|
+
return <D cn={CN("rounded flex flex-col items-center", dashed && "border border-dashed border-zinc-700", rcn(props))} grow={grow} gap={gap ?? 4} p={p ?? 4} wd={wd} ht={ht}>
|
|
90
91
|
{label && <span className="opacity-75">{label}</span>}
|
|
91
92
|
<div className={CN(row ? "flex-row" : "flex-col", "flex items-center")} style={{ gap: sc(gap ?? 4) }}>{children}</div>
|
|
92
93
|
</D>
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
export const BlockSm = (props: DProps & { dashed?: boolean }) => {
|
|
96
|
-
const { children, dashed, grow, gap, p } = props
|
|
97
|
-
return <D cn={CN("rounded text-sm", dashed && "border border-dashed border-zinc-700", rcn(props))} grow={grow} gap={gap} p={p ?? 2}
|
|
97
|
+
const { children, dashed, grow, gap, p, wd, ht } = props
|
|
98
|
+
return <D cn={CN("rounded text-sm", dashed && "border border-dashed border-zinc-700", rcn(props))} grow={grow} gap={gap} p={p ?? 2} wd={wd} ht={ht}
|
|
98
99
|
style={{ paddingLeft: sc(3), paddingRight: sc(3) }}>{children}</D>
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
export const Chip = (props: DProps & { click?: () => void }) => {
|
|
102
|
-
const { children, click, grow, gap, p, wd, style } = props
|
|
103
|
+
const { children, click, grow, gap, p, wd, ht, style } = props
|
|
103
104
|
return <span className={CN("bg-zinc-800 rounded px-2 py-0.5 text-xs", click && "cursor-pointer hover:bg-zinc-700", rcn(props))}
|
|
104
|
-
style={dStyle({ gap, p, wd, style })}
|
|
105
|
+
style={dStyle({ gap, p, wd, ht, style })}
|
|
105
106
|
onClick={click}>{children}</span>
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
export const Card = (props: DProps) => {
|
|
109
|
-
const { children, grow, gap, p } = props
|
|
110
|
-
return <D cn={CN("rounded border border-zinc-700 bg-zinc-900", rcn(props))} grow={grow} gap={gap ?? 4} p={p ?? 4}
|
|
110
|
+
const { children, grow, gap, p, wd, ht } = props
|
|
111
|
+
return <D cn={CN("rounded border border-zinc-700 bg-zinc-900", rcn(props))} grow={grow} gap={gap ?? 4} p={p ?? 4} wd={wd} ht={ht}
|
|
111
112
|
style={{ display: 'flex', flexDirection: 'column' }}>{children}</D>
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
export const Col = (props: DProps) => {
|
|
115
|
-
const { children, grow, gap, p } = props
|
|
116
|
-
return <D cn={CN("flex flex-col", rcn(props))} grow={grow} gap={gap ?? 4} p={p}>{children}</D>
|
|
115
|
+
export const Col = (props: DProps & { align?: 'start' | 'center' | 'end' }) => {
|
|
116
|
+
const { children, grow, gap, p, wd, ht, align } = props
|
|
117
|
+
return <D cn={CN("flex flex-col", align === 'start' && 'items-start', align === 'center' && 'items-center', align === 'end' && 'items-end', rcn(props))} grow={grow} gap={gap ?? 4} p={p} wd={wd} ht={ht}>{children}</D>
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
export const Popover = (props: DProps & { text: ReactNode, color?: Color }) => {
|
|
@@ -134,7 +135,7 @@ export const Muted = (props: DProps) => {
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
export const A = ({
|
|
137
|
-
children, cn, cnIgnoreWrongUsage, grow, gap, p, style, click, href, onClick, onKeyDown, role, tabIndex, ...rest
|
|
138
|
+
children, cn, cnIgnoreWrongUsage, grow, gap, p, wd, style, click, href, onClick, onKeyDown, role, tabIndex, ...rest
|
|
138
139
|
}: DProps & { click?: () => void } & React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
|
|
139
140
|
const c = rcn({ cn, cnIgnoreWrongUsage })
|
|
140
141
|
const fire = (e: React.MouseEvent<HTMLAnchorElement> | React.KeyboardEvent<HTMLAnchorElement>) => {
|
|
@@ -149,7 +150,7 @@ export const A = ({
|
|
|
149
150
|
role={buttonLike ? role ?? 'button' : role}
|
|
150
151
|
tabIndex={buttonLike ? tabIndex ?? 0 : tabIndex}
|
|
151
152
|
className={CN("inline-flex items-center gap-1 text-zinc-300 underline underline-offset-4 cursor-pointer hover:text-zinc-100", grow && "flex-1", c)}
|
|
152
|
-
style={dStyle({ gap, p, style })}
|
|
153
|
+
style={dStyle({ gap, p, wd, style })}
|
|
153
154
|
onClick={fire}
|
|
154
155
|
onKeyDown={e => {
|
|
155
156
|
if (buttonLike && (e.key === 'Enter' || e.key === ' ')) {
|
|
@@ -169,25 +170,25 @@ export const Btn = ({ children, grow, gap, p, click, color, ghost, sm, ...rest }
|
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
export const Tint = (props: DProps & { color: Color }) => {
|
|
172
|
-
const { children, color, grow, gap, p } = props
|
|
173
|
-
return <D cn={CN("rounded text-sm", tintCn(color), rcn(props))} grow={grow} gap={gap} p={p ?? 3}>{children}</D>
|
|
173
|
+
const { children, color, grow, gap, p, wd, ht } = props
|
|
174
|
+
return <D cn={CN("rounded text-sm", tintCn(color), rcn(props))} grow={grow} gap={gap} p={p ?? 3} wd={wd} ht={ht}>{children}</D>
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
export const Row = (props: DProps & { ratio?: number, align?: 'mid' | 'start' | 'end' }) => {
|
|
177
|
-
const { children, ratio, align, grow, gap, p, wd, style } = props
|
|
178
|
+
const { children, ratio, align, grow, gap, p, wd, ht, style } = props
|
|
178
179
|
return <div className={CN("flex items-center justify-center", align === 'mid' && "justify-between", align == 'end' && "justify-end", align == 'start' && "justify-start", grow && "flex-1", rcn(props))}
|
|
179
|
-
style={{ ...dStyle({ gap: gap ?? 4, p, wd, style }), ...(ratio ? { width: `${ratio * 100}%` } : {}) }}>{children}</div>
|
|
180
|
+
style={{ ...dStyle({ gap: gap ?? 4, p, wd, ht, style }), ...(ratio ? { width: `${ratio * 100}%` } : {}) }}>{children}</div>
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
export const Toolbar = (props: DProps) => {
|
|
183
|
-
const { children, gap, p } = props
|
|
184
|
-
return <Row cn={CN("border-b border-zinc-700", rcn(props))} gap={gap} p={p ?? 2} align="mid">{children}</Row>
|
|
184
|
+
const { children, gap, p, wd, ht } = props
|
|
185
|
+
return <Row cn={CN("border-b border-zinc-700", rcn(props))} gap={gap} p={p ?? 2} wd={wd} ht={ht} align="mid">{children}</Row>
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
export const Modal = (props: DProps & { open: boolean }) => {
|
|
188
|
-
const { children, open, gap, p } = props
|
|
189
|
+
const { children, open, gap, p, wd, ht } = props
|
|
189
190
|
return open ? <div className="fixed inset-0 flex items-center justify-center bg-black/50 z-50">
|
|
190
|
-
<Card cn={CN("max-h-[80vh] overflow-y-auto w-lg", rcn(props))} gap={gap} p={p}>{children}</Card>
|
|
191
|
+
<Card cn={CN("max-h-[80vh] overflow-y-auto w-lg", rcn(props))} gap={gap} p={p} wd={wd} ht={ht}>{children}</Card>
|
|
191
192
|
</div> : null
|
|
192
193
|
}
|
|
193
194
|
|
|
@@ -196,9 +197,9 @@ export const Input = ({ cn, cnIgnoreWrongUsage, grow, ...rest }: DProps & React.
|
|
|
196
197
|
return <input className={CN("rounded bg-zinc-800 border border-zinc-700 px-3 py-2 text-sm outline-none", grow && "flex-1", c)} style={dStyle({ gap: rest.gap, p: rest.p, wd: rest.wd, style: rest.style })} {...rest} />
|
|
197
198
|
}
|
|
198
199
|
|
|
199
|
-
export const Textarea = ({ cn, cnIgnoreWrongUsage, grow, ...rest }: DProps & React.TextareaHTMLAttributes<HTMLTextAreaElement>) => {
|
|
200
|
+
export const Textarea = ({ cn, cnIgnoreWrongUsage, ref, grow, ...rest }: DProps & React.TextareaHTMLAttributes<HTMLTextAreaElement> & { ref?: React.RefObject<HTMLTextAreaElement | null> }) => {
|
|
200
201
|
const c = rcn({ cn, cnIgnoreWrongUsage })
|
|
201
|
-
return <textarea className={CN("rounded bg-zinc-800 border border-zinc-700 px-3 py-2 text-sm outline-none w-full", grow && "flex-1", c)} style={dStyle({ gap: rest.gap, p: rest.p, wd: rest.wd, style: rest.style })} {...rest} />
|
|
202
|
+
return <textarea ref={ref} className={CN("rounded bg-zinc-800 border border-zinc-700 px-3 py-2 text-sm outline-none w-full", grow && "flex-1", c)} style={dStyle({ gap: rest.gap, p: rest.p, wd: rest.wd, style: rest.style })} {...rest} />
|
|
202
203
|
}
|
|
203
204
|
|
|
204
205
|
export const Select = ({ cn, cnIgnoreWrongUsage, grow, ...rest }: DProps & React.SelectHTMLAttributes<HTMLSelectElement>) => {
|
|
@@ -207,8 +208,8 @@ export const Select = ({ cn, cnIgnoreWrongUsage, grow, ...rest }: DProps & React
|
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
export const Grid = (props: DProps & { cols?: number }) => {
|
|
210
|
-
const { children, cols, grow, gap, p } = props
|
|
211
|
-
return <D cn={CN("grid ui-grid", rcn(props))} grow={grow} p={p} style={{ gap: sc(gap ?? 4), '--cols': cols ?? Children.count(children) } as React.CSSProperties}>{children}</D>
|
|
211
|
+
const { children, cols, grow, gap, p, wd, ht } = props
|
|
212
|
+
return <D cn={CN("grid ui-grid", rcn(props))} grow={grow} p={p} wd={wd} ht={ht} style={{ gap: sc(gap ?? 4), '--cols': cols ?? Children.count(children) } as React.CSSProperties}>{children}</D>
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
export const Hr = ({ vertical, color = 'gray', grow, gap, p, ...rest }: DProps & { vertical?: boolean, color?: Color | 'gray' }) => {
|
package/package.json
CHANGED
package/styles.css
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
@import "highlight.js/styles/github-dark.css";
|
|
2
2
|
|
|
3
3
|
.ui-markdown { line-height: 1.5; }
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
h1, .ui-markdown h2, .ui-markdown h3 { font-weight: 700; margin: 0; }
|
|
5
|
+
h1 { font-size: 1.5em; }
|
|
6
|
+
h2 { font-size: 1.25em; }
|
|
7
|
+
h3 { font-size: 1.1em; }
|
|
8
|
+
p { margin: 0.4em 0; }
|
|
9
|
+
a { color: #93c5fd; text-decoration: underline; }
|
|
10
|
+
pre { background: #1a1a2e; border-radius: 4px; padding: 0; overflow-x: auto; margin: 0.4em 0; }
|
|
11
|
+
code { font-family: ui-monospace, monospace; font-size: 0.9em; }
|
|
12
|
+
blockquote { border-left: 3px solid #444; padding-left: 1em; opacity: 0.8; margin: 0.25em 0; }
|
|
13
|
+
img { max-width: 100%; border-radius: 6px; }
|
|
9
14
|
.ui-markdown p:first-child { margin-top: 0; }
|
|
10
15
|
.ui-markdown p:last-child { margin-bottom: 0; }
|
|
11
|
-
.ui-markdown pre { background: #1a1a2e; border-radius: 4px; padding: 0; overflow-x: auto; margin: 0.4em 0; }
|
|
12
|
-
.ui-markdown code { font-family: ui-monospace, monospace; font-size: 0.9em; }
|
|
13
16
|
.ui-markdown :not(pre) > code { background: #1a1a2e; padding: 2px 5px; border-radius: 3px; }
|
|
14
17
|
.ui-markdown ul, .ui-markdown ol { padding-left: 1.5em; margin: 0.25em 0; }
|
|
15
|
-
.ui-markdown blockquote { border-left: 3px solid #444; padding-left: 1em; opacity: 0.8; margin: 0.25em 0; }
|
|
16
|
-
.ui-markdown a { color: #93c5fd; text-decoration: underline; }
|
|
17
18
|
.ui-markdown table { border-collapse: collapse; margin: 0.4em 0; }
|
|
18
19
|
.ui-markdown th, .ui-markdown td { border: 1px solid #333; padding: 4px 10px; }
|
|
19
|
-
.ui-markdown img { max-width: 100%; border-radius: 6px; }
|
|
20
|
-
|
|
21
20
|
.ui-grid { grid-template-columns: repeat(var(--cols), 1fr); }
|
|
22
21
|
@media (max-width: 640px) { .ui-grid { grid-template-columns: 1fr; } }
|