Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ui): fix class reactivity and add new `cn` utility for classes (#996)

dev-rb3ae307b3006c
diff --git a/js/app/bun.lock b/js/app/bun.lock
index 67b99ae3e6..24a03998b6 100644
--- a/js/app/bun.lock
+++ b/js/app/bun.lock
@@ -67,6 +67,7 @@
"async-lock": "^1.4.1",
"async-mutex": "^0.5.0",
"brace-expansion": "^4.0.1",
+ "clsx": "^2.1.1",
"cmdk-solid": "^1.1.2",
"codemirror": "^6.0.2",
"colorjs.io": "^0.5.2",
@@ -1591,6 +1592,8 @@
"clone": ["[email protected]", "", {}, "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg=="],
+ "clsx": ["[email protected]", "", {}, "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA=="],
+
"cmdk-solid": ["[email protected]", "", { "dependencies": { "@kobalte/core": "^0.12.4", "@kobalte/utils": "^0.9.0", "@solid-primitives/deep": "^0.2.7", "@solid-primitives/mutation-observer": "^1.1.17" }, "peerDependencies": { "solid-js": "^1.8.0" } }, "sha512-E0g6bwr2Z92Ib1K2WHwGsq6xsrkVVSN1oe5YTg8LCV3iIwtyZORwmR+8n0xrecqycdhgAar8vWUjtB1OJt9tiA=="],
"code-point-at": ["[email protected]", "", {}, "sha512-RpAVKQA5T63xEj6/giIbUEtZwJ4UFIc3ZtvEkiaUERylqe8xb5IvqcgOurZLahv93CLKfxcw5YI+DZcUBRyLXA=="],
diff --git a/js/app/package.json b/js/app/package.json
index f01745d4da..c46a749144 100644
--- a/js/app/package.json
+++ b/js/app/package.json
@@ -82,6 +82,7 @@
"async-lock": "^1.4.1",
"async-mutex": "^0.5.0",
"brace-expansion": "^4.0.1",
+ "clsx": "^2.1.1",
"cmdk-solid": "^1.1.2",
"codemirror": "^6.0.2",
"colorjs.io": "^0.5.2",
diff --git a/js/app/packages/ui/components/Button.tsx b/js/app/packages/ui/components/Button.tsx
index a97e7a9230..c3f45db730 100644
--- a/js/app/packages/ui/components/Button.tsx
+++ b/js/app/packages/ui/components/Button.tsx
@@ -1,7 +1,7 @@
import CaretDown from '@phosphor-icons/core/regular/caret-down.svg';
+import { cn } from '@ui/utils/classname';
import { Tooltip } from 'core/component/Tooltip';
import { type JSX, type ParentComponent, Show, splitProps } from 'solid-js';
-import { twMerge } from 'tailwind-merge';
type ButtonProps = JSX.ButtonHTMLAttributes<HTMLButtonElement> & {
variant?: 'primary' | 'secondary' | 'tertiary' | 'destructive';
@@ -39,24 +39,11 @@ export const Button: ParentComponent<ButtonProps> = (props) => {
'variant',
'class',
'children',
- 'classList',
'tooltip',
'showChevron',
'type',
]);
- const classes = twMerge(
- 'relative flex items-center justify-center gap-[1ch] px-[1ch] py-[0.25lh] border border-transparent',
- 'font-mono font-medium uppercase leading-none',
- 'hover:bg-surface-4',
- 'focus:[--focus-border-inset:-4px]',
- 'active:border-accent active:bg-accent active:text-panel',
- 'disabled:opacity-50 disabled:cursor-not-allowed',
-
- // Anything added by the caller will granularly override
- local.class
- );
-
function MaybeWrapInTooltip(props: { children: JSX.Element }) {
if (!local.tooltip) return props.children;
@@ -67,16 +54,24 @@ export const Button: ParentComponent<ButtonProps> = (props) => {
<MaybeWrapInTooltip>
<button
type={local.type ?? 'button'}
- class={classes}
- classList={{
- 'bg-ink border-ink text-panel hover:bg-accent! hover:opacity-80 active:opacity-100':
- 'primary' === local.variant,
- 'border-ink!': 'secondary' === local.variant,
- 'border-failure! text-failure active:bg-failure hover:bg-failure-bg!':
- 'destructive' === local.variant,
- 'p-0! gap-0! items-stretch': !!local.showChevron,
- ...(local.classList ?? {}),
- }}
+ class={cn(
+ 'relative flex items-center justify-center gap-[1ch] px-[1ch] py-[0.25lh] border border-transparent',
+ 'font-mono font-medium uppercase leading-none',
+ 'hover:bg-surface-4',
+ 'focus:[--focus-border-inset:-4px]',
+ 'active:border-accent active:bg-accent active:text-panel',
+ 'disabled:opacity-50 disabled:cursor-not-allowed',
+ {
+ 'bg-ink border-ink text-panel hover:bg-accent hover:opacity-80 active:opacity-100':
+ 'primary' === local.variant,
+ 'border-ink': 'secondary' === local.variant,
+ 'border-failure text-failure active:bg-failure hover:bg-failure-bg':
+ 'destructive' === local.variant,
+ 'p-0 gap-0 items-stretch': local.showChevron,
+ },
+ // Anything added by the caller will granularly override
+ local.class
+ )}
{...buttonAttributes}
>
{local.children}
diff --git a/js/app/packages/ui/utils/classname.ts b/js/app/packages/ui/utils/classname.ts
new file mode 100644
index 0000000000..0c7d77dc62
--- /dev/null
+++ b/js/app/packages/ui/utils/classname.ts
@@ -0,0 +1,6 @@
+import { twMerge } from 'tailwind-merge';
+import { clsx, type ClassValue } from 'clsx';
+
+export const cn = (...args: ClassValue[]) => {
+ return twMerge(clsx(args));
+};