bref-ui 0.3.0 → 0.3.1

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.
@@ -8,5 +8,6 @@ export * from './text-input/index.ts';
8
8
  export * from './slider/index.ts';
9
9
  export * from './progress-bar/index.ts';
10
10
  export * from './pill/index.ts';
11
+ export * from './pill-selection/index.ts';
11
12
  export * from './select/index.ts';
12
13
  export * from './toggle/index.ts';
@@ -8,5 +8,6 @@ export * from "./text-input/index.js";
8
8
  export * from "./slider/index.js";
9
9
  export * from "./progress-bar/index.js";
10
10
  export * from "./pill/index.js";
11
+ export * from "./pill-selection/index.js";
11
12
  export * from "./select/index.js";
12
13
  export * from "./toggle/index.js";
@@ -1,5 +1,4 @@
1
1
  <script lang="ts">
2
- import type { SvelteHTMLElements } from 'svelte/elements';
3
2
  import type { PillProps } from './types.js';
4
3
  import Icon from '../icon/icon.svelte';
5
4
 
@@ -8,11 +7,24 @@
8
7
  size = 'medium',
9
8
  color = 'primary',
10
9
  variant = 'filled',
11
- icon
10
+ icon,
11
+ onClick,
12
+ disabled = false
12
13
  }: PillProps = $props();
14
+
15
+ const handleClick = () => {
16
+ if (!disabled && onClick) onClick();
17
+ };
13
18
  </script>
14
19
 
15
- <div class={`${size} ${color} ${variant}`}>
20
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
21
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
22
+ <div
23
+ class={`${size} ${color} ${variant}`}
24
+ class:clickable={!!onClick}
25
+ class:disabled
26
+ onclick={handleClick}
27
+ >
16
28
  {#if icon}
17
29
  <Icon contrastMode={variant === 'filled'} {color} {...icon} {size} />
18
30
  {/if}
@@ -20,6 +32,10 @@
20
32
  </div>
21
33
 
22
34
  <style>
35
+ div,
36
+ span {
37
+ transition: all 0.2s ease-in-out;
38
+ }
23
39
  div {
24
40
  /* Size defaults (medium) */
25
41
  --internal-pill-padding-y: calc(var(--spacing) * 0.375);
@@ -41,6 +57,15 @@
41
57
  border-radius: 4rem;
42
58
  }
43
59
 
60
+ div.clickable {
61
+ cursor: pointer;
62
+ }
63
+
64
+ div.disabled {
65
+ opacity: 0.4;
66
+ cursor: not-allowed;
67
+ }
68
+
44
69
  span {
45
70
  white-space: nowrap;
46
71
  color: inherit;
@@ -6,4 +6,6 @@ export interface PillProps {
6
6
  color?: Color;
7
7
  variant?: Variant;
8
8
  icon?: Pick<IconProps, 'name' | 'filled' | 'ariaLabel'>;
9
+ onClick?: () => void;
10
+ disabled?: boolean;
9
11
  }
@@ -0,0 +1,2 @@
1
+ export { default as PillSelection } from './pill-selection.svelte';
2
+ export * from './types.ts';
@@ -0,0 +1,2 @@
1
+ export { default as PillSelection } from './pill-selection.svelte';
2
+ export * from "./types.js";
@@ -0,0 +1,48 @@
1
+ <script lang="ts">
2
+ import type { PillSelectionProps } from './types.js';
3
+ import Pill from '../pill/pill.svelte';
4
+
5
+ const {
6
+ items,
7
+ selection,
8
+ onSelect,
9
+ maxSelectionLength,
10
+ disableOthersOnFull = false,
11
+ size = 'medium',
12
+ color = 'primary'
13
+ }: PillSelectionProps = $props();
14
+
15
+ const isFull = $derived(
16
+ maxSelectionLength !== undefined && selection.length >= maxSelectionLength
17
+ );
18
+
19
+ const handleClick = (id: string) => {
20
+ const selected = selection.includes(id);
21
+ if (selected) onSelect(selection.filter((s) => s !== id));
22
+ else if (isFull && !disableOthersOnFull) onSelect([...selection.slice(1), id]);
23
+ else if (!isFull) onSelect([...selection, id]);
24
+ };
25
+ </script>
26
+
27
+ <div>
28
+ {#each items as item}
29
+ {@const selected = selection.includes(item.id)}
30
+ <Pill
31
+ label={item.label}
32
+ icon={item.icon}
33
+ {size}
34
+ {color}
35
+ variant={selected ? 'filled' : 'soft'}
36
+ disabled={disableOthersOnFull && isFull && !selected}
37
+ onClick={() => handleClick(item.id)}
38
+ />
39
+ {/each}
40
+ </div>
41
+
42
+ <style>
43
+ div {
44
+ display: flex;
45
+ flex-wrap: wrap;
46
+ gap: 0.5rem;
47
+ }
48
+ </style>
@@ -0,0 +1,4 @@
1
+ import type { PillSelectionProps } from './types.ts';
2
+ declare const PillSelection: import("svelte").Component<PillSelectionProps, {}, "">;
3
+ type PillSelection = ReturnType<typeof PillSelection>;
4
+ export default PillSelection;
@@ -0,0 +1,16 @@
1
+ import type { IconProps } from '../icon/types.ts';
2
+ import type { Color, Size } from '../types.ts';
3
+ export interface PillSelectionItem {
4
+ id: string;
5
+ label: string;
6
+ icon?: Pick<IconProps, 'name' | 'filled' | 'ariaLabel'>;
7
+ }
8
+ export interface PillSelectionProps {
9
+ items: PillSelectionItem[];
10
+ selection: string[];
11
+ onSelect: (selection: string[]) => void;
12
+ maxSelectionLength?: number;
13
+ disableOthersOnFull?: boolean;
14
+ size?: Size;
15
+ color?: Color;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bref-ui",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A Svelte UI component library using scoped CSS - minimal and flexible",
5
5
  "license": "MIT",
6
6
  "author": "feuerstein",