b44ui 0.0.5 → 0.0.6

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/README.md CHANGED
@@ -7,7 +7,7 @@ minimal dark-mode react components, via tailwind
7
7
 
8
8
  pnpm add b44ui
9
9
 
10
- echo 'optimizeDeps: { include: ["highlight.js"] }' >> vite.config.ts
10
+ echo 'optimizeDeps: { include: ["b44ui", "highlight.js"] }' >> vite.config.ts
11
11
 
12
12
  echo '@import "tailwindcss";
13
13
  @source "../node_modules/b44ui/index.tsx";
package/index.tsx CHANGED
@@ -7,51 +7,82 @@ import clsx from "clsx"
7
7
  import { twMerge } from "tailwind-merge"
8
8
 
9
9
  export type Color = 'red' | 'blue' | 'orange' | 'purple' | 'yellow'
10
- const tintCn = (c: Color) => `bg-${c}-500/20 border-${c}-500`
11
- const colorCn = (c: Color) => `bg-${c}-600 hover:bg-${c}-500`
10
+ const tintMap: Record<Color, string> = {
11
+ red: 'bg-red-500/20 border-red-500',
12
+ blue: 'bg-blue-500/20 border-blue-500',
13
+ orange: 'bg-orange-500/20 border-orange-500',
14
+ purple: 'bg-purple-500/20 border-purple-500',
15
+ yellow: 'bg-yellow-500/20 border-yellow-500',
16
+ }
17
+ const colorMap: Record<Color, string> = {
18
+ red: 'bg-red-600 hover:bg-red-500',
19
+ blue: 'bg-blue-600 hover:bg-blue-500',
20
+ orange: 'bg-orange-600 hover:bg-orange-500',
21
+ purple: 'bg-purple-600 hover:bg-purple-500',
22
+ yellow: 'bg-yellow-600 hover:bg-yellow-500',
23
+ }
24
+ const tintCn = (c: Color) => tintMap[c]
25
+ const colorCn = (c: Color) => colorMap[c]
12
26
 
13
27
  export const CN = (...inputs: ClassValue[]) => twMerge(clsx(inputs))
14
28
 
15
- export type DProps = { children?: ReactNode, cn?: any, style?: React.CSSProperties, grow?: boolean }
16
- export const D = ({ children, cn, style, grow }: DProps) =>
17
- <div className={CN(cn, grow && "flex-1")} style={style}>{children}</div>
29
+ const sc = (n?: number) => n !== undefined ? n * 4 : undefined // tailwind scale -> px
18
30
 
19
- export const App = ({ children, center = true, width, cn }: DProps & { center?: boolean, width?: number }) => {
20
- const inner = Children.map(children, c => typeof c == 'string' ? <Md>{c.trim()}</Md> : c)
31
+ export type DProps = {
32
+ children?: ReactNode
33
+ cn?: any
34
+ style?: React.CSSProperties
35
+ grow?: boolean
36
+ gap?: number
37
+ p?: number
38
+ }
21
39
 
22
- return <D cn={["min-h-screen w-full bg-[#111] text-[#eee] font-[Inter]", center && "flex justify-center items-center", cn]}>
40
+ const dStyle = ({ gap, p, style }: DProps): React.CSSProperties | undefined => {
41
+ const g = sc(gap), pd = sc(p)
42
+ if (!g && !pd && !style) return undefined
43
+ return { ...(g !== undefined && { gap: g }), ...(pd !== undefined && { padding: pd }), ...style }
44
+ }
45
+
46
+ export const D = (props: DProps) =>
47
+ <div className={CN(props.cn, props.grow && "flex-1")} style={dStyle(props)}>{props.children}</div>
48
+
49
+ export const App = ({ children, center = true, width, cn, gap, p }: DProps & { center?: boolean, width?: number }) => {
50
+ const inner = Children.map(children, c => typeof c == 'string' ? <Md>{c.trim()}</Md> : c)
51
+ return <D cn={["min-h-screen w-full bg-[#111] text-[#eee] font-[Inter]", center && "flex justify-center items-center", cn]} gap={gap} p={p}>
23
52
  {center ? <div className="max-w-full px-5 py-10 space-y-5 *:mx-auto" style={{ width }}>{inner}</div> : inner}
24
53
  </D>
25
54
  }
26
55
 
27
- export const Centered = ({ children, cn, grow, width = 700 }: DProps & { width?: number }) =>
28
- <D cn={["mx-auto max-w-full px-6", cn]} grow={grow} style={{ width }}>{children}</D>
56
+ export const Centered = ({ children, cn, grow, gap, p, width = 700 }: DProps & { width?: number }) =>
57
+ <D cn={["mx-auto max-w-full px-6", cn]} grow={grow} gap={gap} p={p} style={{ width }}>{children}</D>
29
58
 
30
- export const Block = ({ label, children, row, dashed, cn, grow }: DProps & { label?: ReactNode, row?: boolean, dashed?: boolean }) =>
31
- <D cn={["rounded p-4 flex flex-col items-center gap-2", dashed && "border border-dashed border-zinc-700", cn]} grow={grow}>
59
+ export const Block = ({ label, children, row, dashed, cn, grow, gap, p }: DProps & { label?: ReactNode, row?: boolean, dashed?: boolean }) =>
60
+ <D cn={["rounded flex flex-col items-center", dashed && "border border-dashed border-zinc-700", cn]} grow={grow} gap={gap ?? 4} p={p ?? 4}>
32
61
  {label && <span className="opacity-75">{label}</span>}
33
- <div className={CN(row ? "flex-row" : "flex-col", "flex items-center gap-2")}>{children}</div>
62
+ <div className={CN(row ? "flex-row" : "flex-col", "flex items-center")} style={{ gap: sc(gap ?? 4) }}>{children}</div>
34
63
  </D>
35
64
 
36
- export const BlockSm = ({ children, dashed, cn, grow }: DProps & { dashed?: boolean }) =>
37
- <D cn={["rounded px-3 py-2 text-sm", dashed && "border border-dashed border-zinc-700", cn]} grow={grow}>{children}</D>
65
+ export const BlockSm = ({ children, dashed, cn, grow, gap, p }: DProps & { dashed?: boolean }) =>
66
+ <D cn={["rounded text-sm", dashed && "border border-dashed border-zinc-700", cn]} grow={grow} gap={gap} p={p ?? 2}
67
+ style={{ paddingLeft: sc(3), paddingRight: sc(3) }}>{children}</D>
38
68
 
39
69
  export const Chip = ({ children, cn, click }: DProps & { click?: () => void }) =>
40
70
  <span className={CN("bg-zinc-800 rounded px-2 py-0.5 text-xs", click && "cursor-pointer hover:bg-zinc-700", cn)}
41
71
  onClick={click}>{children}</span>
42
72
 
43
- export const Card = ({ children, cn, grow }: DProps) =>
44
- <D cn={["rounded border border-zinc-700 bg-zinc-900 p-4 space-y-3", cn]} grow={grow}>{children}</D>
73
+ export const Card = ({ children, cn, grow, gap, p }: DProps) =>
74
+ <D cn={["rounded border border-zinc-700 bg-zinc-900", cn]} grow={grow} gap={gap ?? 4} p={p ?? 4}
75
+ style={{ display: 'flex', flexDirection: 'column' }}>{children}</D>
45
76
 
46
- export const Col = ({ children, cn, grow }: DProps) =>
47
- <D cn={["flex flex-col gap-3", cn]} grow={grow}>{children}</D>
77
+ export const Col = ({ children, cn, grow, gap, p }: DProps) =>
78
+ <D cn={["flex flex-col", cn]} grow={grow} gap={gap ?? 4} p={p}>{children}</D>
48
79
 
49
80
  export const Popover = ({ children, text, color, cn }: DProps & { text: ReactNode, color?: Color }) => {
50
81
  const [open, setOpen] = useState(false)
51
82
  return <span className="relative inline-block" onMouseEnter={() => setOpen(true)} onMouseLeave={() => setOpen(false)}>
52
83
  <span className={CN("cursor-pointer", color && tintCn(color), color && "border-b-2", cn)}>{children}</span>
53
84
  {open && <div className="absolute left-0 top-full z-10 mt-1">
54
- <Card cn="w-64 p-3 shadow-lg text-sm">{text}</Card>
85
+ <Card cn="w-64 shadow-lg text-sm" p={3}>{text}</Card>
55
86
  </div>}
56
87
  </span>
57
88
  }
@@ -59,21 +90,24 @@ export const Popover = ({ children, text, color, cn }: DProps & { text: ReactNod
59
90
  export const Muted = ({ children, cn, grow }: DProps) =>
60
91
  <span className={CN("text-sm text-zinc-400", grow && "flex-1", cn)}>{children}</span>
61
92
 
62
- export const Btn = ({ children, cn, grow, click, color, ghost, ...rest }: DProps & { click?: () => void, color?: Color, ghost?: boolean } & React.ButtonHTMLAttributes<HTMLButtonElement>) =>
63
- <button className={CN("rounded px-4 py-2 text-sm cursor-pointer",
93
+ export const Btn = ({ children, cn, grow, gap, p, click, color, ghost, sm, ...rest }: DProps & { click?: () => void, color?: Color, ghost?: boolean, sm?: boolean } & React.ButtonHTMLAttributes<HTMLButtonElement>) =>
94
+ <button className={CN("rounded cursor-pointer", sm ? "px-3 py-1 text-xs" : "px-4 py-2 text-sm",
64
95
  ghost ? "bg-transparent text-zinc-400 hover:bg-zinc-800" : color ? colorCn(color) : "bg-zinc-800 hover:bg-zinc-700", grow && "flex-1", cn)}
65
- onClick={click} {...rest}>{children}</button>
96
+ style={dStyle({ gap, p })} onClick={click} {...rest}>{children}</button>
97
+
98
+ export const Tint = ({ children, color, cn, grow, gap, p }: DProps & { color: Color }) =>
99
+ <D cn={["rounded text-sm", tintCn(color), cn]} grow={grow} gap={gap} p={p ?? 3}>{children}</D>
66
100
 
67
- export const Tint = ({ children, color, cn, grow }: DProps & { color: Color }) =>
68
- <D cn={["p-3 rounded text-sm", tintCn(color), cn]} grow={grow}>{children}</D>
101
+ export const Row = ({ children, ratio, align, cn, grow, gap, p }: DProps & { ratio?: number, align?: 'mid' | 'start' | 'end' }) =>
102
+ <div className={CN("flex items-center justify-center", align === 'mid' && "justify-between", align == 'end' && "justify-end", align == 'start' && "justify-start", grow && "flex-1", cn)}
103
+ style={{ gap: sc(gap ?? 4), ...(p !== undefined && { padding: sc(p) }), ...(ratio ? { width: `${ratio * 100}%` } : {}) }}>{children}</div>
69
104
 
70
- export const Row = ({ children, ratio, align, cn, grow }: DProps & { ratio?: number, align?: 'mid' | 'start' | 'end' }) =>
71
- <div className={CN("flex gap-2 items-center", align === 'mid' && "justify-between", align == 'end' && "justify-end", align == 'start' && "justify-start", grow && "flex-1", cn)}
72
- style={ratio ? { width: `${ratio * 100}%` } : undefined}>{children}</div>
105
+ export const Toolbar = ({ children, cn, gap, p }: DProps) =>
106
+ <Row cn={["border-b border-zinc-700", cn]} gap={gap} p={p ?? 2} align="mid">{children}</Row>
73
107
 
74
- export const Modal = ({ children, open, cn }: DProps & { open: boolean }) =>
108
+ export const Modal = ({ children, open, cn, gap, p }: DProps & { open: boolean }) =>
75
109
  open ? <div className="fixed inset-0 flex items-center justify-center bg-black/50 z-50">
76
- <Card cn={["max-h-[80vh] overflow-y-auto w-lg", cn]}>{children}</Card>
110
+ <Card cn={["max-h-[80vh] overflow-y-auto w-lg", cn]} gap={gap} p={p}>{children}</Card>
77
111
  </div> : null
78
112
 
79
113
  export const Input = ({ cn, grow, ...rest }: { cn?: any, grow?: boolean } & React.InputHTMLAttributes<HTMLInputElement>) =>
@@ -85,8 +119,8 @@ export const Textarea = ({ cn, grow, ...rest }: { cn?: any, grow?: boolean } & R
85
119
  export const Select = ({ cn, grow, ...rest }: { cn?: any, grow?: boolean } & React.SelectHTMLAttributes<HTMLSelectElement>) =>
86
120
  <select className={CN("rounded bg-zinc-800 border border-zinc-700 px-3 py-2 text-sm outline-none cursor-pointer", grow && "flex-1", cn)} {...rest} />
87
121
 
88
- export const Grid = ({ children, cols, cn, grow }: DProps & { cols?: number }) =>
89
- <D cn={["grid gap-4", cn]} grow={grow} style={{ gridTemplateColumns: `repeat(${cols ?? Children.count(children)}, 1fr)` }}>{children}</D>
122
+ export const Grid = ({ children, cols, cn, grow, gap, p }: DProps & { cols?: number }) =>
123
+ <D cn={["grid", cn]} grow={grow} p={p} style={{ gap: sc(gap ?? 4), gridTemplateColumns: `repeat(${cols ?? Children.count(children)}, 1fr)` }}>{children}</D>
90
124
 
91
125
  const marked = new Marked(markedHighlight({ langPrefix: "hljs language-", highlight: c => hljs.highlightAuto(c).value }))
92
126
  export const Md = ({ children, className }: { children: string, className?: string }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "b44ui",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "npm run dev --prefix example"
package/styles.css CHANGED
@@ -1,18 +1,19 @@
1
1
  @import "highlight.js/styles/github-dark.css";
2
2
 
3
- /* markdown - todo rewrite in tailwind */
4
- :root { line-height: 1.6; }
5
- h1, h2, h3 { font-weight: 700; margin: 1em 0 0.5em; }
6
- h1 { font-size: 1.5em; }
7
- h2 { font-size: 1.25em; }
8
- h3 { font-size: 1.1em; }
9
- p { margin: 1em 0; }
10
- pre { background: #1a1a2e; border-radius: 4px; padding: 0; overflow-x: auto; margin: 0.75em 0; }
11
- code { font-family: ui-monospace, monospace; font-size: 0.9em; padding: 4px; }
12
- :not(pre) > code { background: #1a1a2e; padding: 2px 5px; border-radius: 3px; }
13
- ul, ol { padding-left: 1.5em; margin: 0.5em 0; }
14
- blockquote { border-left: 3px solid #444; padding-left: 1em; opacity: 0.8; margin: 0.5em 0; }
15
- a { color: #93c5fd; text-decoration: underline; }
16
- table { border-collapse: collapse; margin: 0.75em 0; }
17
- th, td { border: 1px solid #333; padding: 6px 12px; }
18
- img { max-width: 100%; border-radius: 6px; }
3
+ .ui-markdown { line-height: 1.5; }
4
+ .ui-markdown h1, .ui-markdown h2, .ui-markdown h3 { font-weight: 700; margin: 0; }
5
+ .ui-markdown h1 { font-size: 1.5em; }
6
+ .ui-markdown h2 { font-size: 1.25em; }
7
+ .ui-markdown h3 { font-size: 1.1em; }
8
+ .ui-markdown p { margin: 0.4em 0; }
9
+ .ui-markdown p:first-child { margin-top: 0; }
10
+ .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
+ .ui-markdown :not(pre) > code { background: #1a1a2e; padding: 2px 5px; border-radius: 3px; }
14
+ .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
+ .ui-markdown table { border-collapse: collapse; margin: 0.4em 0; }
18
+ .ui-markdown th, .ui-markdown td { border: 1px solid #333; padding: 4px 10px; }
19
+ .ui-markdown img { max-width: 100%; border-radius: 6px; }