Skip to content

Commit b326ebc

Browse files
committed
Merge branch 'feat/improve-ui-component-library' of https://github.com/TanStack/devtools into feat/improve-ui-component-library
2 parents f117db9 + f327677 commit b326ebc

2 files changed

Lines changed: 59 additions & 36 deletions

File tree

packages/devtools-ui/src/components/button.tsx

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
import { splitProps } from 'solid-js';
2-
import clsx from 'clsx';
3-
import { useStyles } from '../styles/use-styles';
4-
import type { JSX } from 'solid-js';
1+
import { splitProps } from 'solid-js'
2+
import clsx from 'clsx'
3+
import { useStyles } from '../styles/use-styles'
4+
import type { JSX } from 'solid-js'
55

6-
export type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'success' | 'info' | 'warning';
6+
export type ButtonVariant =
7+
| 'primary'
8+
| 'secondary'
9+
| 'danger'
10+
| 'success'
11+
| 'info'
12+
| 'warning'
713
type ButtonProps = JSX.ButtonHTMLAttributes<HTMLButtonElement> & {
8-
variant?: ButtonVariant;
9-
outline?: boolean;
10-
ghost?: boolean;
11-
children?: any;
12-
className?: string;
13-
};
14+
variant?: ButtonVariant
15+
outline?: boolean
16+
ghost?: boolean
17+
children?: any
18+
className?: string
19+
}
1420

1521
export function Button(props: ButtonProps) {
1622
const styles = useStyles()
17-
const [local, rest] = splitProps(props, ['variant', 'outline', 'ghost', 'children', 'className']);
18-
const variant = local.variant || 'primary';
19-
const classes = clsx(styles().button.base, styles().button.variant(variant, local.outline, local.ghost), local.className)
23+
const [local, rest] = splitProps(props, [
24+
'variant',
25+
'outline',
26+
'ghost',
27+
'children',
28+
'className',
29+
])
30+
const variant = local.variant || 'primary'
31+
const classes = clsx(
32+
styles().button.base,
33+
styles().button.variant(variant, local.outline, local.ghost),
34+
local.className,
35+
)
2036

2137
return (
2238
<button {...rest} class={classes}>

packages/devtools-ui/src/styles/use-styles.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { createSignal } from 'solid-js'
33
import { tokens } from './tokens'
44
import type { ButtonVariant } from '../components/button'
55

6-
const buttonVariantColors: Record<ButtonVariant, { bg: string; hover: string; active: string; text: string; border: string }> = {
6+
const buttonVariantColors: Record<
7+
ButtonVariant,
8+
{ bg: string; hover: string; active: string; text: string; border: string }
9+
> = {
710
primary: {
811
bg: tokens.colors.purple[500],
912
hover: tokens.colors.purple[600],
@@ -46,8 +49,8 @@ const buttonVariantColors: Record<ButtonVariant, { bg: string; hover: string; ac
4649
text: '#fff',
4750
border: tokens.colors.green[500],
4851
},
49-
};
50-
const stylesFactory = (theme: 'light' | 'dark' = "dark") => {
52+
}
53+
const stylesFactory = (theme: 'light' | 'dark' = 'dark') => {
5154
const { colors, font, size, alpha } = tokens
5255
const { fontFamily } = font
5356
const css = goober.css
@@ -240,22 +243,26 @@ const stylesFactory = (theme: 'light' | 'dark' = "dark") => {
240243
`,
241244
button: {
242245
base: css`
243-
display: inline-flex;
244-
align-items: center;
245-
justify-content: center;
246-
font-family: ${tokens.font.fontFamily.sans};
247-
font-size: 0.8rem;
248-
font-weight: 500;
249-
border-radius: 0.2rem;
250-
padding: 0.2rem 0.6rem;
251-
cursor: pointer;
252-
transition: background 0.2s, color 0.2s, border 0.2s, box-shadow 0.2s;
253-
outline: none;
254-
border-width: 1px;
255-
border-style: solid;
256-
`,
246+
display: inline-flex;
247+
align-items: center;
248+
justify-content: center;
249+
font-family: ${tokens.font.fontFamily.sans};
250+
font-size: 0.8rem;
251+
font-weight: 500;
252+
border-radius: 0.2rem;
253+
padding: 0.2rem 0.6rem;
254+
cursor: pointer;
255+
transition:
256+
background 0.2s,
257+
color 0.2s,
258+
border 0.2s,
259+
box-shadow 0.2s;
260+
outline: none;
261+
border-width: 1px;
262+
border-style: solid;
263+
`,
257264
variant(variant: ButtonVariant, outline?: boolean, ghost?: boolean) {
258-
const v = buttonVariantColors[variant];
265+
const v = buttonVariantColors[variant]
259266
if (ghost) {
260267
return goober.css`
261268
background: transparent;
@@ -267,7 +274,7 @@ const stylesFactory = (theme: 'light' | 'dark' = "dark") => {
267274
&:active {
268275
background: ${tokens.colors.purple[200]};
269276
}
270-
`;
277+
`
271278
}
272279
if (outline) {
273280
return goober.css`
@@ -282,7 +289,7 @@ const stylesFactory = (theme: 'light' | 'dark' = "dark") => {
282289
background: ${tokens.colors.purple[200]};
283290
border-color: ${v.active};
284291
}
285-
`;
292+
`
286293
}
287294
// Default solid button
288295
return goober.css`
@@ -297,8 +304,8 @@ const stylesFactory = (theme: 'light' | 'dark' = "dark") => {
297304
background: ${v.active};
298305
border-color: ${v.active};
299306
}
300-
`;
301-
}
307+
`
308+
},
302309
},
303310
tag: {
304311
dot: (color: keyof typeof tokens.colors) => css`

0 commit comments

Comments
 (0)