diff --git a/pkgs/clan-app/ui/src/components/Form/MachineTags.tsx b/pkgs/clan-app/ui/src/components/Form/MachineTags.tsx index 34a510233..3fbb02fdd 100644 --- a/pkgs/clan-app/ui/src/components/Form/MachineTags.tsx +++ b/pkgs/clan-app/ui/src/components/Form/MachineTags.tsx @@ -164,17 +164,26 @@ export const MachineTags = (props: MachineTagsProps) => { {(option) => ( state.remove(option), - } + interactive={ + !(option.disabled || props.disabled || props.readOnly) } - /> + icon={({ inverted }) => + option.disabled || + props.disabled || + props.readOnly ? undefined : ( + state.remove(option)} + /> + ) + } + > + {option.value} + )} diff --git a/pkgs/clan-app/ui/src/components/Tag/Tag.css b/pkgs/clan-app/ui/src/components/Tag/Tag.css index d34014854..719db1a73 100644 --- a/pkgs/clan-app/ui/src/components/Tag/Tag.css +++ b/pkgs/clan-app/ui/src/components/Tag/Tag.css @@ -19,7 +19,9 @@ span.tag { &.has-action { @apply pr-1.5; + } + &.is-interactive { &:hover { @apply bg-def-acc-3; } diff --git a/pkgs/clan-app/ui/src/components/Tag/Tag.stories.tsx b/pkgs/clan-app/ui/src/components/Tag/Tag.stories.tsx index 328bf1618..19cd67f06 100644 --- a/pkgs/clan-app/ui/src/components/Tag/Tag.stories.tsx +++ b/pkgs/clan-app/ui/src/components/Tag/Tag.stories.tsx @@ -1,6 +1,7 @@ import { Tag, TagProps } from "@/src/components/Tag/Tag"; import { Meta, type StoryContext, StoryObj } from "@kachurun/storybook-solid"; -import { expect, fn } from "storybook/test"; +import { fn } from "storybook/test"; +import Icon from "../Icon/Icon"; const meta: Meta = { title: "Components/Tag", @@ -13,27 +14,44 @@ type Story = StoryObj; export const Default: Story = { args: { - label: "Label", + children: "Label", }, }; +const IconAction = ({ + inverted, + handleActionClick, +}: { + inverted: boolean; + handleActionClick: () => void; +}) => ( + { + console.log("icon clicked"); + handleActionClick(); + fn(); + }} + inverted={inverted} + /> +); export const WithAction: Story = { args: { ...Default.args, - action: { - icon: "Close", - onClick: fn(), - }, + icon: IconAction, + interactive: true, }, play: async ({ canvas, step, userEvent, args }: StoryContext) => { await userEvent.click(canvas.getByRole("button")); - await expect(args.action.onClick).toHaveBeenCalled(); + // await expect(args.icon.onClick).toHaveBeenCalled(); }, }; export const Inverted: Story = { args: { - label: "Label", + children: "Label", inverted: true, }, }; diff --git a/pkgs/clan-app/ui/src/components/Tag/Tag.tsx b/pkgs/clan-app/ui/src/components/Tag/Tag.tsx index c82ba8e08..d065aa06b 100644 --- a/pkgs/clan-app/ui/src/components/Tag/Tag.tsx +++ b/pkgs/clan-app/ui/src/components/Tag/Tag.tsx @@ -2,18 +2,19 @@ import "./Tag.css"; import cx from "classnames"; import { Typography } from "@/src/components/Typography/Typography"; -import { createSignal, Show } from "solid-js"; -import Icon, { IconVariant } from "../Icon/Icon"; +import { createSignal, JSX } from "solid-js"; -export interface TagAction { - icon: IconVariant; - onClick: () => void; +interface IconActionProps { + inverted: boolean; + handleActionClick: () => void; } -export interface TagProps { - label: string; - action?: TagAction; +export interface TagProps extends JSX.HTMLAttributes { + children?: JSX.Element; + icon?: (state: IconActionProps) => JSX.Element; inverted?: boolean; + interactive?: boolean; + class?: string; } export const Tag = (props: TagProps) => { @@ -23,7 +24,6 @@ export const Tag = (props: TagProps) => { const handleActionClick = () => { setIsActive(true); - props.action?.onClick(); setTimeout(() => setIsActive(false), 150); }; @@ -32,23 +32,18 @@ export const Tag = (props: TagProps) => { class={cx("tag", { inverted: inverted(), active: isActive(), - "has-action": props.action, + "has-icon": props.icon, + "is-interactive": props.interactive, + class: props.class, })} - aria-label={props.label} - aria-readonly={!props.action} > - {props.label} + {props.children} - - - + {props.icon?.({ + inverted: inverted(), + handleActionClick, + })} ); }; diff --git a/pkgs/clan-app/ui/src/components/TagGroup/TagGroup.tsx b/pkgs/clan-app/ui/src/components/TagGroup/TagGroup.tsx index 455665cc6..3dd2ca4cf 100644 --- a/pkgs/clan-app/ui/src/components/TagGroup/TagGroup.tsx +++ b/pkgs/clan-app/ui/src/components/TagGroup/TagGroup.tsx @@ -15,7 +15,7 @@ export const TagGroup = (props: TagGroupProps) => { return (
- {(label) => } + {(label) => {label}}
);