periplo-ui 4.15.1 → 4.16.0

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.
@@ -1,26 +1,32 @@
1
1
  import { VariantProps } from 'class-variance-authority';
2
2
  import * as React from 'react';
3
+ type ChipVariant = 'default' | 'ghost' | 'primary' | 'secondary' | 'error' | 'success' | 'tint' | 'dashed' | 'subtle';
3
4
  declare const chipVariants: (props?: ({
4
- variant?: "primary" | "success" | "error" | "secondary" | "ghost" | "default" | null | undefined;
5
+ variant?: "primary" | "success" | "error" | "secondary" | "ghost" | "dashed" | "default" | "tint" | "subtle" | null | undefined;
5
6
  size?: "sm" | "md" | "lg" | null | undefined;
6
7
  rounded?: "square" | "full" | null | undefined;
7
8
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
8
- export type ChipProps = {
9
+ type ChipSize = 'sm' | 'md' | 'lg';
10
+ type ChipBaseProps = {
9
11
  /**
10
12
  * The visual style of the chip.
11
13
  * @default default
12
14
  */
13
- variant?: 'default' | 'ghost' | 'primary' | 'secondary' | 'error' | 'success';
15
+ variant?: ChipVariant;
14
16
  /**
15
17
  * The size of the chip, affecting padding and font size.
16
18
  * @default md
17
19
  */
18
- size?: 'sm' | 'md' | 'lg';
20
+ size?: ChipSize;
19
21
  /**
20
22
  * The roundedness of the chip, affecting the border radius.
21
23
  * @default full
22
24
  */
23
25
  rounded?: 'full' | 'square';
26
+ /**
27
+ * An optional leading icon, rendered before the chip's content (e.g. a lock or plus icon).
28
+ */
29
+ icon?: React.ReactNode;
24
30
  /**
25
31
  * Optional callback for when the remove button is clicked.
26
32
  * When provided, displays a remove button on the chip.
@@ -40,7 +46,24 @@ export type ChipProps = {
40
46
  * Additional CSS classes to apply to the chip.
41
47
  */
42
48
  className?: string;
43
- } & React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof chipVariants>;
49
+ } & Omit<React.HTMLAttributes<HTMLDivElement>, 'onClick'> & VariantProps<typeof chipVariants>;
50
+ export type ChipProps = ChipBaseProps & ({
51
+ /**
52
+ * Wraps the chip's content in an inner, keyboard-accessible button, so it can be pressed
53
+ * (e.g. to open a related panel). Required to use `onClick`.
54
+ */
55
+ pressable: true;
56
+ /**
57
+ * Click handler, fired on the inner button.
58
+ */
59
+ onClick?: React.MouseEventHandler<HTMLElement>;
60
+ } | {
61
+ /**
62
+ * @default false
63
+ */
64
+ pressable?: false;
65
+ onClick?: never;
66
+ });
44
67
  /**
45
68
  * A chip component for displaying compact information with optional remove functionality.
46
69
  *
@@ -55,12 +78,18 @@ export type ChipProps = {
55
78
  * <Chip variant="primary">Primary</Chip>
56
79
  * <Chip variant="error">Error</Chip>
57
80
  *
81
+ * // With a leading icon (e.g. locked or add state)
82
+ * <Chip variant="tint" icon={<LockIcon size={14} />}>Locked</Chip>
83
+ *
84
+ * // Pressable, to open a related panel
85
+ * <Chip pressable onClick={() => console.log('pressed')}>Pressable</Chip>
86
+ *
58
87
  * // Inside button context (e.g., Combobox)
59
88
  * <Chip onRemove={() => console.log('removed')} triggerElement="span">
60
89
  * Inside Button
61
90
  * </Chip>
62
91
  */
63
- declare function Chip({ className, variant, size, rounded, onRemove, triggerElement, children, ...props }: ChipProps): React.JSX.Element;
92
+ declare function Chip({ className, variant, size, rounded, icon, pressable, onClick, onRemove, triggerElement, children, ...props }: ChipProps): React.JSX.Element;
64
93
  declare namespace Chip {
65
94
  var displayName: string;
66
95
  }
@@ -1,10 +1,10 @@
1
1
  import { cn } from "../../../lib/utils.js";
2
2
  import { cva } from "class-variance-authority";
3
3
  import "react";
4
- import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { XIcon } from "@phosphor-icons/react/dist/ssr/X";
6
6
  //#region src/components/data-display/Chip/Chip.tsx
7
- var chipVariants = cva("inline-flex items-center border font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", {
7
+ var chipVariants = cva("relative inline-flex items-center gap-1.5 border font-medium transition-colors has-[[data-chip-trigger]:focus-visible]:ring-2 has-[[data-chip-trigger]:focus-visible]:ring-ring has-[[data-chip-trigger]:focus-visible]:ring-offset-2", {
8
8
  variants: {
9
9
  /**
10
10
  * Defines the visual style of the chip
@@ -15,15 +15,18 @@ var chipVariants = cva("inline-flex items-center border font-medium transition-c
15
15
  primary: "border-transparent bg-primary text-primary-foreground",
16
16
  secondary: "border-transparent bg-neutral-950 text-neutral-foreground",
17
17
  error: "border-transparent bg-error-600 text-white",
18
- success: "border-transparent bg-success-600 text-white"
18
+ success: "border-transparent bg-success-600 text-white",
19
+ tint: "border-primary-500 bg-background-200 text-neutral-950 has-[[data-chip-trigger]:focus-visible]:ring-primary-500",
20
+ dashed: "border-dashed border-primary-500 bg-white text-neutral-950 has-[[data-chip-trigger]:focus-visible]:border-solid has-[[data-chip-trigger]:focus-visible]:ring-primary-500",
21
+ subtle: "border-transparent bg-white text-neutral-950 has-[[data-chip-trigger]:focus-visible]:border-primary-500 has-[[data-chip-trigger]:focus-visible]:ring-primary-500"
19
22
  },
20
23
  /**
21
- * Controls the size and padding of the chip
24
+ * Controls the height and font size of the chip.
22
25
  */
23
26
  size: {
24
- sm: "px-2.5 py-0.5 text-sm",
25
- md: "px-2.5 py-1 text-sm",
26
- lg: "px-3 py-1 text-md"
27
+ sm: "h-7 text-sm",
28
+ md: "h-8 text-sm",
29
+ lg: "h-9 text-md"
27
30
  },
28
31
  rounded: {
29
32
  full: "rounded-full",
@@ -36,6 +39,37 @@ var chipVariants = cva("inline-flex items-center border font-medium transition-c
36
39
  rounded: "full"
37
40
  }
38
41
  });
42
+ var CHIP_PADDING = {
43
+ sm: "px-2.5 py-0.5",
44
+ md: "px-2.5 py-1",
45
+ lg: "px-3 py-1"
46
+ };
47
+ var CHIP_REMOVE_SIZE = {
48
+ sm: "h-5 w-5",
49
+ md: "h-6 w-6",
50
+ lg: "h-7 w-7"
51
+ };
52
+ var CHIP_REMOVE_ICON_SIZE = {
53
+ sm: 12,
54
+ md: 16,
55
+ lg: 18
56
+ };
57
+ var CHIP_PRESSABLE_REMOVE_GAP = {
58
+ sm: "pr-7",
59
+ md: "pr-8",
60
+ lg: "pr-9"
61
+ };
62
+ var CHIP_PRESSABLE_HOVER = {
63
+ default: "[@media(hover:_hover)]:has-[:hover]:bg-neutral-200",
64
+ ghost: "[@media(hover:_hover)]:has-[:hover]:bg-neutral-100/50",
65
+ primary: "[@media(hover:_hover)]:has-[:hover]:bg-primary-700",
66
+ secondary: "[@media(hover:_hover)]:has-[:hover]:bg-neutral-800",
67
+ error: "[@media(hover:_hover)]:has-[:hover]:bg-error-800",
68
+ success: "[@media(hover:_hover)]:has-[:hover]:bg-success-800",
69
+ tint: "[@media(hover:_hover)]:has-[:hover]:bg-background-300",
70
+ dashed: "[@media(hover:_hover)]:has-[:hover]:bg-neutral-50",
71
+ subtle: "[@media(hover:_hover)]:has-[:hover]:bg-neutral-100"
72
+ };
39
73
  /**
40
74
  * A chip component for displaying compact information with optional remove functionality.
41
75
  *
@@ -50,40 +84,56 @@ var chipVariants = cva("inline-flex items-center border font-medium transition-c
50
84
  * <Chip variant="primary">Primary</Chip>
51
85
  * <Chip variant="error">Error</Chip>
52
86
  *
87
+ * // With a leading icon (e.g. locked or add state)
88
+ * <Chip variant="tint" icon={<LockIcon size={14} />}>Locked</Chip>
89
+ *
90
+ * // Pressable, to open a related panel
91
+ * <Chip pressable onClick={() => console.log('pressed')}>Pressable</Chip>
92
+ *
53
93
  * // Inside button context (e.g., Combobox)
54
94
  * <Chip onRemove={() => console.log('removed')} triggerElement="span">
55
95
  * Inside Button
56
96
  * </Chip>
57
97
  */
58
- function Chip({ className, variant = "default", size = "md", rounded = "full", onRemove, triggerElement = "button", children, ...props }) {
59
- const removeIconClasses = "focus-visible:ring-ring inline-flex h-6 w-6 items-center justify-center rounded-full transition-colors hover:bg-black/10 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none";
98
+ function Chip({ className, variant = "default", size = "md", rounded = "full", icon, pressable = false, onClick, onRemove, triggerElement = "button", children, ...props }) {
99
+ const removeIconClasses = cn("focus-visible:ring-ring inline-flex cursor-pointer items-center justify-center rounded-full transition-colors hover:bg-black/10 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden", CHIP_REMOVE_SIZE[size]);
60
100
  const RemoveElement = triggerElement;
101
+ const removeTriggerProps = triggerElement === "button" ? { type: "button" } : {
102
+ role: "button",
103
+ tabIndex: 0
104
+ };
105
+ const paddingClasses = cn(CHIP_PADDING[size], onRemove && "pr-1");
106
+ const pressableContentPadding = cn(CHIP_PADDING[size], onRemove && CHIP_PRESSABLE_REMOVE_GAP[size]);
61
107
  return /* @__PURE__ */ jsxs("div", {
62
108
  className: cn(chipVariants({
63
109
  variant,
64
110
  size,
65
111
  rounded
66
- }), onRemove && "gap-1.5 pr-1", className),
112
+ }), pressable && CHIP_PRESSABLE_HOVER[variant], !pressable && paddingClasses, className),
67
113
  ...props,
68
- children: [children, onRemove ? /* @__PURE__ */ jsx(RemoveElement, {
69
- ...triggerElement === "button" ? { type: "button" } : {},
70
- role: triggerElement === "span" ? "button" : void 0,
71
- tabIndex: triggerElement === "span" ? 0 : void 0,
72
- onKeyDown: (event) => {
114
+ children: [pressable ? /* @__PURE__ */ jsxs("button", {
115
+ type: "button",
116
+ "data-chip-trigger": true,
117
+ className: cn("inline-flex cursor-pointer items-center gap-1.5 rounded-[inherit] focus-visible:outline-hidden", pressableContentPadding),
118
+ onClick,
119
+ children: [icon, children]
120
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [icon, children] }), onRemove ? /* @__PURE__ */ jsx(RemoveElement, {
121
+ ...removeTriggerProps,
122
+ onKeyDown: triggerElement === "span" ? (event) => {
73
123
  if (event.key === "Enter" || event.key === " ") {
74
124
  event.preventDefault();
75
125
  onRemove(event);
76
126
  }
77
- },
127
+ } : void 0,
78
128
  onMouseDown: (event) => {
79
129
  event.preventDefault();
80
130
  event.stopPropagation();
81
131
  },
82
132
  onClick: onRemove,
83
- className: removeIconClasses,
133
+ className: cn(removeIconClasses, pressable && "absolute top-1/2 right-1 -translate-y-1/2"),
84
134
  "aria-label": "Remove",
85
135
  children: /* @__PURE__ */ jsx(XIcon, {
86
- size: 16,
136
+ size: CHIP_REMOVE_ICON_SIZE[size],
87
137
  weight: "regular",
88
138
  className: "shrink-0"
89
139
  })
@@ -1 +1 @@
1
- {"version":3,"file":"Chip.js","names":[],"sources":["../../../../src/components/data-display/Chip/Chip.tsx"],"sourcesContent":["import { XIcon } from '@phosphor-icons/react/dist/ssr/X'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport * as React from 'react'\n\nimport { cn } from '@/lib/utils'\n\nconst chipVariants = cva(\n 'inline-flex items-center border font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',\n {\n variants: {\n /**\n * Defines the visual style of the chip\n */\n variant: {\n default: 'border-transparent bg-neutral-100 text-default-foreground',\n ghost: ' bg-transparent border border-neutral-500 text-primary-foreground',\n primary: 'border-transparent bg-primary text-primary-foreground',\n secondary: 'border-transparent bg-neutral-950 text-neutral-foreground',\n error: 'border-transparent bg-error-600 text-white',\n success: 'border-transparent bg-success-600 text-white',\n },\n /**\n * Controls the size and padding of the chip\n */\n size: {\n sm: 'px-2.5 py-0.5 text-sm',\n md: 'px-2.5 py-1 text-sm',\n lg: 'px-3 py-1 text-md',\n },\n rounded: {\n full: 'rounded-full',\n square: 'rounded-sm',\n },\n },\n defaultVariants: {\n variant: 'default',\n size: 'md',\n rounded: 'full',\n },\n },\n)\n\nexport type ChipProps = {\n /**\n * The visual style of the chip.\n * @default default\n */\n variant?: 'default' | 'ghost' | 'primary' | 'secondary' | 'error' | 'success'\n\n /**\n * The size of the chip, affecting padding and font size.\n * @default md\n */\n size?: 'sm' | 'md' | 'lg'\n\n /**\n * The roundedness of the chip, affecting the border radius.\n * @default full\n */\n rounded?: 'full' | 'square'\n\n /**\n * Optional callback for when the remove button is clicked.\n * When provided, displays a remove button on the chip.\n */\n onRemove?: (\n event:\n | React.KeyboardEvent<HTMLButtonElement | HTMLSpanElement>\n | React.MouseEvent<HTMLButtonElement | HTMLSpanElement, MouseEvent>,\n ) => void\n\n /**\n * The HTML element to use for the remove trigger.\n * Use 'span' when the chip is inside a button context to avoid nested buttons.\n * @default 'button'\n */\n triggerElement?: 'button' | 'span'\n\n /**\n * The content to display inside the chip.\n */\n children?: React.ReactNode\n\n /**\n * Additional CSS classes to apply to the chip.\n */\n className?: string\n} & React.HTMLAttributes<HTMLDivElement> &\n VariantProps<typeof chipVariants>\n\n/**\n * A chip component for displaying compact information with optional remove functionality.\n *\n * @example\n * // Basic usage\n * <Chip>Label</Chip>\n *\n * // With remove button\n * <Chip onRemove={() => console.log('removed')}>Removable</Chip>\n *\n * // Different variants\n * <Chip variant=\"primary\">Primary</Chip>\n * <Chip variant=\"error\">Error</Chip>\n *\n * // Inside button context (e.g., Combobox)\n * <Chip onRemove={() => console.log('removed')} triggerElement=\"span\">\n * Inside Button\n * </Chip>\n */\nfunction Chip({\n className,\n variant = 'default',\n size = 'md',\n rounded = 'full',\n onRemove,\n triggerElement = 'button',\n children,\n ...props\n}: ChipProps) {\n const removeIconClasses =\n 'focus-visible:ring-ring inline-flex h-6 w-6 items-center justify-center rounded-full transition-colors hover:bg-black/10 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none'\n\n const RemoveElement = triggerElement\n\n return (\n <div className={cn(chipVariants({ variant, size, rounded }), onRemove && 'gap-1.5 pr-1', className)} {...props}>\n {children}\n {onRemove ? (\n <RemoveElement\n {...(triggerElement === 'button' ? { type: 'button' as const } : {})}\n role={triggerElement === 'span' ? 'button' : undefined}\n tabIndex={triggerElement === 'span' ? 0 : undefined}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault()\n onRemove(event)\n }\n }}\n onMouseDown={(event) => {\n event.preventDefault()\n event.stopPropagation()\n }}\n onClick={onRemove}\n className={removeIconClasses}\n aria-label=\"Remove\"\n >\n <XIcon size={16} weight=\"regular\" className=\"shrink-0\" />\n </RemoveElement>\n ) : null}\n </div>\n )\n}\nChip.displayName = 'Chip'\n\nexport { Chip, chipVariants }\n"],"mappings":";;;;;;AAMA,IAAM,eAAe,IACnB,qIACA;CACE,UAAU;;;;EAIR,SAAS;GACP,SAAS;GACT,OAAO;GACP,SAAS;GACT,WAAW;GACX,OAAO;GACP,SAAS;EACX;;;;EAIA,MAAM;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;EACN;EACA,SAAS;GACP,MAAM;GACN,QAAQ;EACV;CACF;CACA,iBAAiB;EACf,SAAS;EACT,MAAM;EACN,SAAS;CACX;AACF,CACF;;;;;;;;;;;;;;;;;;;;AAqEA,SAAS,KAAK,EACZ,WACA,UAAU,WACV,OAAO,MACP,UAAU,QACV,UACA,iBAAiB,UACjB,UACA,GAAG,SACS;CACZ,MAAM,oBACJ;CAEF,MAAM,gBAAgB;CAEtB,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,aAAa;GAAE;GAAS;GAAM;EAAQ,CAAC,GAAG,YAAY,gBAAgB,SAAS;EAAG,GAAI;EAAzG,UAAA,CACG,UACA,WACC,oBAAC,eAAD;GACE,GAAK,mBAAmB,WAAW,EAAE,MAAM,SAAkB,IAAI,CAAC;GAClE,MAAM,mBAAmB,SAAS,WAAW,KAAA;GAC7C,UAAU,mBAAmB,SAAS,IAAI,KAAA;GAC1C,YAAY,UAAU;IACpB,IAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;KAC9C,MAAM,eAAe;KACrB,SAAS,KAAK;IAChB;GACF;GACA,cAAc,UAAU;IACtB,MAAM,eAAe;IACrB,MAAM,gBAAgB;GACxB;GACA,SAAS;GACT,WAAW;GACX,cAAW;GAEX,UAAA,oBAAC,OAAD;IAAO,MAAM;IAAI,QAAO;IAAU,WAAU;GAAY,CAAA;EAC3C,CAAA,IACb,IACD;;AAET;AACA,KAAK,cAAc"}
1
+ {"version":3,"file":"Chip.js","names":["_Fragment"],"sources":["../../../../src/components/data-display/Chip/Chip.tsx"],"sourcesContent":["import { XIcon } from '@phosphor-icons/react/dist/ssr/X'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport * as React from 'react'\n\nimport { cn } from '@/lib/utils'\n\ntype ChipVariant = 'default' | 'ghost' | 'primary' | 'secondary' | 'error' | 'success' | 'tint' | 'dashed' | 'subtle'\n\nconst chipVariants = cva(\n 'relative inline-flex items-center gap-1.5 border font-medium transition-colors has-[[data-chip-trigger]:focus-visible]:ring-2 has-[[data-chip-trigger]:focus-visible]:ring-ring has-[[data-chip-trigger]:focus-visible]:ring-offset-2',\n {\n variants: {\n /**\n * Defines the visual style of the chip\n */\n variant: {\n default: 'border-transparent bg-neutral-100 text-default-foreground',\n ghost: ' bg-transparent border border-neutral-500 text-primary-foreground',\n primary: 'border-transparent bg-primary text-primary-foreground',\n secondary: 'border-transparent bg-neutral-950 text-neutral-foreground',\n error: 'border-transparent bg-error-600 text-white',\n success: 'border-transparent bg-success-600 text-white',\n tint: 'border-primary-500 bg-background-200 text-neutral-950 has-[[data-chip-trigger]:focus-visible]:ring-primary-500',\n dashed:\n 'border-dashed border-primary-500 bg-white text-neutral-950 has-[[data-chip-trigger]:focus-visible]:border-solid has-[[data-chip-trigger]:focus-visible]:ring-primary-500',\n subtle:\n 'border-transparent bg-white text-neutral-950 has-[[data-chip-trigger]:focus-visible]:border-primary-500 has-[[data-chip-trigger]:focus-visible]:ring-primary-500',\n },\n /**\n * Controls the height and font size of the chip.\n */\n size: {\n sm: 'h-7 text-sm',\n md: 'h-8 text-sm',\n lg: 'h-9 text-md',\n },\n rounded: {\n full: 'rounded-full',\n square: 'rounded-sm',\n },\n },\n defaultVariants: {\n variant: 'default',\n size: 'md',\n rounded: 'full',\n },\n },\n)\n\ntype ChipSize = 'sm' | 'md' | 'lg'\n\nconst CHIP_PADDING: Record<ChipSize, string> = {\n sm: 'px-2.5 py-0.5',\n md: 'px-2.5 py-1',\n lg: 'px-3 py-1',\n}\n\nconst CHIP_REMOVE_SIZE: Record<ChipSize, string> = {\n sm: 'h-5 w-5',\n md: 'h-6 w-6',\n lg: 'h-7 w-7',\n}\n\nconst CHIP_REMOVE_ICON_SIZE: Record<ChipSize, number> = {\n sm: 12,\n md: 16,\n lg: 18,\n}\n\n// Reserves room, in the pressable button's own padding, for the absolutely positioned remove\n// control at this size: its diameter (CHIP_REMOVE_SIZE) plus its right-1 inset plus a label gap.\nconst CHIP_PRESSABLE_REMOVE_GAP: Record<ChipSize, string> = {\n sm: 'pr-7',\n md: 'pr-8',\n lg: 'pr-9',\n}\n\n// Keyed off :has(:hover) on the root so hovering the remove button also shows the chip's own hover state.\n// Gated behind the hover media feature (like Tailwind's own hover: variant) so a tap on a touch\n// device doesn't leave the background stuck in its \"hovered\" state until the user taps elsewhere.\nconst CHIP_PRESSABLE_HOVER: Record<ChipVariant, string> = {\n default: '[@media(hover:_hover)]:has-[:hover]:bg-neutral-200',\n ghost: '[@media(hover:_hover)]:has-[:hover]:bg-neutral-100/50',\n primary: '[@media(hover:_hover)]:has-[:hover]:bg-primary-700',\n secondary: '[@media(hover:_hover)]:has-[:hover]:bg-neutral-800',\n error: '[@media(hover:_hover)]:has-[:hover]:bg-error-800',\n success: '[@media(hover:_hover)]:has-[:hover]:bg-success-800',\n tint: '[@media(hover:_hover)]:has-[:hover]:bg-background-300',\n dashed: '[@media(hover:_hover)]:has-[:hover]:bg-neutral-50',\n subtle: '[@media(hover:_hover)]:has-[:hover]:bg-neutral-100',\n}\n\ntype ChipBaseProps = {\n /**\n * The visual style of the chip.\n * @default default\n */\n variant?: ChipVariant\n\n /**\n * The size of the chip, affecting padding and font size.\n * @default md\n */\n size?: ChipSize\n\n /**\n * The roundedness of the chip, affecting the border radius.\n * @default full\n */\n rounded?: 'full' | 'square'\n\n /**\n * An optional leading icon, rendered before the chip's content (e.g. a lock or plus icon).\n */\n icon?: React.ReactNode\n\n /**\n * Optional callback for when the remove button is clicked.\n * When provided, displays a remove button on the chip.\n */\n onRemove?: (\n event:\n | React.KeyboardEvent<HTMLButtonElement | HTMLSpanElement>\n | React.MouseEvent<HTMLButtonElement | HTMLSpanElement, MouseEvent>,\n ) => void\n\n /**\n * The HTML element to use for the remove trigger.\n * Use 'span' when the chip is inside a button context to avoid nested buttons.\n * @default 'button'\n */\n triggerElement?: 'button' | 'span'\n\n /**\n * The content to display inside the chip.\n */\n children?: React.ReactNode\n\n /**\n * Additional CSS classes to apply to the chip.\n */\n className?: string\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'onClick'> &\n VariantProps<typeof chipVariants>\n\nexport type ChipProps = ChipBaseProps &\n (\n | {\n /**\n * Wraps the chip's content in an inner, keyboard-accessible button, so it can be pressed\n * (e.g. to open a related panel). Required to use `onClick`.\n */\n pressable: true\n /**\n * Click handler, fired on the inner button.\n */\n onClick?: React.MouseEventHandler<HTMLElement>\n }\n | {\n /**\n * @default false\n */\n pressable?: false\n onClick?: never\n }\n )\n\n/**\n * A chip component for displaying compact information with optional remove functionality.\n *\n * @example\n * // Basic usage\n * <Chip>Label</Chip>\n *\n * // With remove button\n * <Chip onRemove={() => console.log('removed')}>Removable</Chip>\n *\n * // Different variants\n * <Chip variant=\"primary\">Primary</Chip>\n * <Chip variant=\"error\">Error</Chip>\n *\n * // With a leading icon (e.g. locked or add state)\n * <Chip variant=\"tint\" icon={<LockIcon size={14} />}>Locked</Chip>\n *\n * // Pressable, to open a related panel\n * <Chip pressable onClick={() => console.log('pressed')}>Pressable</Chip>\n *\n * // Inside button context (e.g., Combobox)\n * <Chip onRemove={() => console.log('removed')} triggerElement=\"span\">\n * Inside Button\n * </Chip>\n */\nfunction Chip({\n className,\n variant = 'default',\n size = 'md',\n rounded = 'full',\n icon,\n pressable = false,\n onClick,\n onRemove,\n triggerElement = 'button',\n children,\n ...props\n}: ChipProps) {\n const removeIconClasses = cn(\n 'focus-visible:ring-ring inline-flex cursor-pointer items-center justify-center rounded-full transition-colors hover:bg-black/10 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden',\n CHIP_REMOVE_SIZE[size],\n )\n\n const RemoveElement = triggerElement\n const removeTriggerProps =\n triggerElement === 'button' ? { type: 'button' as const } : { role: 'button' as const, tabIndex: 0 }\n\n const paddingClasses = cn(CHIP_PADDING[size], onRemove && 'pr-1')\n const pressableContentPadding = cn(CHIP_PADDING[size], onRemove && CHIP_PRESSABLE_REMOVE_GAP[size])\n\n return (\n <div\n className={cn(\n chipVariants({ variant, size, rounded }),\n pressable && CHIP_PRESSABLE_HOVER[variant],\n !pressable && paddingClasses,\n className,\n )}\n {...props}\n >\n {pressable ? (\n <button\n type=\"button\"\n data-chip-trigger\n className={cn(\n 'inline-flex cursor-pointer items-center gap-1.5 rounded-[inherit] focus-visible:outline-hidden',\n pressableContentPadding,\n )}\n onClick={onClick}\n >\n {icon}\n {children}\n </button>\n ) : (\n <>\n {icon}\n {children}\n </>\n )}\n {onRemove ? (\n <RemoveElement\n {...removeTriggerProps}\n // Native buttons already turn Enter/Space into a click; only the span fallback needs this.\n onKeyDown={\n triggerElement === 'span'\n ? (event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault()\n onRemove(event)\n }\n }\n : undefined\n }\n onMouseDown={(event) => {\n event.preventDefault()\n event.stopPropagation()\n }}\n onClick={onRemove}\n className={cn(removeIconClasses, pressable && 'absolute top-1/2 right-1 -translate-y-1/2')}\n aria-label=\"Remove\"\n >\n <XIcon size={CHIP_REMOVE_ICON_SIZE[size]} weight=\"regular\" className=\"shrink-0\" />\n </RemoveElement>\n ) : null}\n </div>\n )\n}\nChip.displayName = 'Chip'\n\nexport { Chip, chipVariants }\n"],"mappings":";;;;;;AAQA,IAAM,eAAe,IACnB,yOACA;CACE,UAAU;;;;EAIR,SAAS;GACP,SAAS;GACT,OAAO;GACP,SAAS;GACT,WAAW;GACX,OAAO;GACP,SAAS;GACT,MAAM;GACN,QACE;GACF,QACE;EACJ;;;;EAIA,MAAM;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;EACN;EACA,SAAS;GACP,MAAM;GACN,QAAQ;EACV;CACF;CACA,iBAAiB;EACf,SAAS;EACT,MAAM;EACN,SAAS;CACX;AACF,CACF;AAIA,IAAM,eAAyC;CAC7C,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,IAAM,mBAA6C;CACjD,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,IAAM,wBAAkD;CACtD,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAIA,IAAM,4BAAsD;CAC1D,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAKA,IAAM,uBAAoD;CACxD,SAAS;CACT,OAAO;CACP,SAAS;CACT,WAAW;CACX,OAAO;CACP,SAAS;CACT,MAAM;CACN,QAAQ;CACR,QAAQ;AACV;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,SAAS,KAAK,EACZ,WACA,UAAU,WACV,OAAO,MACP,UAAU,QACV,MACA,YAAY,OACZ,SACA,UACA,iBAAiB,UACjB,UACA,GAAG,SACS;CACZ,MAAM,oBAAoB,GACxB,iNACA,iBAAiB,KACnB;CAEA,MAAM,gBAAgB;CACtB,MAAM,qBACJ,mBAAmB,WAAW,EAAE,MAAM,SAAkB,IAAI;EAAE,MAAM;EAAmB,UAAU;CAAE;CAErG,MAAM,iBAAiB,GAAG,aAAa,OAAO,YAAY,MAAM;CAChE,MAAM,0BAA0B,GAAG,aAAa,OAAO,YAAY,0BAA0B,KAAK;CAElG,OACE,qBAAC,OAAD;EACE,WAAW,GACT,aAAa;GAAE;GAAS;GAAM;EAAQ,CAAC,GACvC,aAAa,qBAAqB,UAClC,CAAC,aAAa,gBACd,SACF;EACA,GAAI;EAPN,UAAA,CASG,YACC,qBAAC,UAAD;GACE,MAAK;GACL,qBAAA;GACA,WAAW,GACT,kGACA,uBACF;GACS;GAPX,UAAA,CASG,MACA,QACK;EAER,CAAA,IAAA,qBAAAA,UAAA,EAAA,UAAA,CACG,MACA,QACD,EAAA,CAAA,GAEH,WACC,oBAAC,eAAD;GACE,GAAI;GAEJ,WACE,mBAAmB,UACd,UAAU;IACT,IAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;KAC9C,MAAM,eAAe;KACrB,SAAS,KAAK;IAChB;GACF,IACA,KAAA;GAEN,cAAc,UAAU;IACtB,MAAM,eAAe;IACrB,MAAM,gBAAgB;GACxB;GACA,SAAS;GACT,WAAW,GAAG,mBAAmB,aAAa,2CAA2C;GACzF,cAAW;GAEX,UAAA,oBAAC,OAAD;IAAO,MAAM,sBAAsB;IAAO,QAAO;IAAU,WAAU;GAAY,CAAA;EACpE,CAAA,IACb,IACD;;AAET;AACA,KAAK,cAAc"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "periplo-ui",
3
3
  "description": "IATI UI library",
4
4
  "private": false,
5
- "version": "4.15.1",
5
+ "version": "4.16.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",