@casinogate/ui 1.3.5 → 1.3.7

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.
@@ -432,6 +432,9 @@
432
432
  .cgui\:min-w-42 {
433
433
  min-width: calc(var(--cgui-spacing) * 42);
434
434
  }
435
+ .cgui\:min-w-fit {
436
+ min-width: fit-content;
437
+ }
435
438
  .cgui\:min-w-px {
436
439
  min-width: 1px;
437
440
  }
@@ -724,6 +727,9 @@
724
727
  .cgui\:px-4 {
725
728
  padding-inline: calc(var(--cgui-spacing) * 4);
726
729
  }
730
+ .cgui\:px-6 {
731
+ padding-inline: calc(var(--cgui-spacing) * 6);
732
+ }
727
733
  .cgui\:py-1 {
728
734
  padding-block: calc(var(--cgui-spacing) * 1);
729
735
  }
@@ -12,6 +12,7 @@
12
12
  ref = $bindable(null),
13
13
  id = useId(uid),
14
14
  children,
15
+ child,
15
16
  class: className,
16
17
  ...props
17
18
  }: SegmentItemProps = $props();
@@ -27,9 +28,13 @@
27
28
 
28
29
  const styles = SegmentStylesContext.get();
29
30
 
30
- const mergedProps = $derived(mergeProps(props, itemState.props));
31
+ const mergedProps = $derived(mergeProps(props, itemState.props, { class: cn(styles.current.item(), className) }));
31
32
  </script>
32
33
 
33
- <button class={cn(styles.current.item(), className)} {...mergedProps}>
34
- {@render children?.()}
35
- </button>
34
+ {#if child}
35
+ {@render child({ props: mergedProps })}
36
+ {:else}
37
+ <button {...mergedProps}>
38
+ {@render children?.()}
39
+ </button>
40
+ {/if}
@@ -17,6 +17,7 @@
17
17
  variant = 'primary',
18
18
  rounded = 'sm',
19
19
  size = 'md',
20
+ spacingX = 'md',
20
21
  onValueChange,
21
22
  ...restProps
22
23
  }: SegmentRootProps = $props();
@@ -37,7 +38,7 @@
37
38
  disabled: box.with(() => disabled),
38
39
  });
39
40
 
40
- const variants = $derived(segmentVariants({ variant, rounded, size }));
41
+ const variants = $derived(segmentVariants({ variant, rounded, size, spacingX }));
41
42
 
42
43
  SegmentStylesContext.set(box.with(() => variants));
43
44
 
@@ -0,0 +1 @@
1
+ export { default as Segment } from './segment.svelte';
@@ -0,0 +1 @@
1
+ export { default as Segment } from './segment.svelte';
@@ -1,2 +1,3 @@
1
1
  export * as SegmentPrimitive from './exports-primitive.js';
2
- export type { SegmentItemProps, SegmentRootProps } from './types.js';
2
+ export * from './exports.js';
3
+ export type { SegmentItemProps, SegmentItemValue, SegmentProps, SegmentRootProps } from './types.js';
@@ -1 +1,2 @@
1
1
  export * as SegmentPrimitive from './exports-primitive.js';
2
+ export * from './exports.js';
@@ -3,11 +3,11 @@
3
3
  import type { Parameters } from '@storybook/sveltekit';
4
4
 
5
5
  import type { ComponentProps } from 'svelte';
6
- import { SegmentPrimitive } from './index.js';
6
+ import { Segment, SegmentPrimitive } from './index.js';
7
7
 
8
8
  const parameters: Parameters = {
9
9
  controls: {
10
- include: ['value', 'disabled', 'size', 'variant', 'rounded'],
10
+ include: ['value', 'disabled', 'size', 'variant', 'rounded', 'spacingX'],
11
11
  },
12
12
  };
13
13
 
@@ -41,3 +41,17 @@
41
41
  {/snippet}
42
42
 
43
43
  <Story name="Basic" {args} {parameters} {template} />
44
+
45
+ <Story name="Preset" {args} {parameters}>
46
+ {#snippet template(args: Args)}
47
+ <Segment
48
+ {...args}
49
+ items={[
50
+ { key: '1', label: 'Segment 1', value: '1' },
51
+ { key: '2', label: 'Segment 2', value: '2' },
52
+ { key: '3', label: 'Segment 3', value: '3' },
53
+ { key: '4', label: 'Segment 4', value: '4' },
54
+ ]}
55
+ />
56
+ {/snippet}
57
+ </Story>
@@ -1,3 +1,4 @@
1
+ import { Segment } from './index.js';
1
2
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
3
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
4
  $$bindings?: Bindings;
@@ -0,0 +1,23 @@
1
+ <script lang="ts">
2
+ import Item from './components/segment.item.svelte';
3
+ import Root from './components/segment.root.svelte';
4
+ import type { SegmentProps } from './types.js';
5
+
6
+ let { items, item: itemSnippet, value = $bindable(''), ref = $bindable(null), ...restProps }: SegmentProps = $props();
7
+ </script>
8
+
9
+ <Root bind:value bind:ref {...restProps}>
10
+ {#each items as item (item.key)}
11
+ {#if itemSnippet}
12
+ <Item value={item.value}>
13
+ {#snippet child({ props })}
14
+ {@render itemSnippet?.({ item, props })}
15
+ {/snippet}
16
+ </Item>
17
+ {:else}
18
+ <Item value={item.value}>
19
+ {item.label}
20
+ </Item>
21
+ {/if}
22
+ {/each}
23
+ </Root>
@@ -0,0 +1,4 @@
1
+ import type { SegmentProps } from './types.js';
2
+ declare const Segment: import("svelte").Component<SegmentProps, {}, "value" | "ref">;
3
+ type Segment = ReturnType<typeof Segment>;
4
+ export default Segment;
@@ -30,6 +30,18 @@ export declare const segmentVariants: import("tailwind-variants").TVReturnType<{
30
30
  item: string[];
31
31
  };
32
32
  };
33
+ spacingX: {
34
+ sm: {
35
+ item: string[];
36
+ };
37
+ md: {
38
+ item: string[];
39
+ };
40
+ lg: {
41
+ item: string[];
42
+ };
43
+ clear: {};
44
+ };
33
45
  }, {
34
46
  root: string[];
35
47
  item: string[];
@@ -63,6 +75,18 @@ export declare const segmentVariants: import("tailwind-variants").TVReturnType<{
63
75
  item: string[];
64
76
  };
65
77
  };
78
+ spacingX: {
79
+ sm: {
80
+ item: string[];
81
+ };
82
+ md: {
83
+ item: string[];
84
+ };
85
+ lg: {
86
+ item: string[];
87
+ };
88
+ clear: {};
89
+ };
66
90
  }, {
67
91
  root: string[];
68
92
  item: string[];
@@ -96,6 +120,18 @@ export declare const segmentVariants: import("tailwind-variants").TVReturnType<{
96
120
  item: string[];
97
121
  };
98
122
  };
123
+ spacingX: {
124
+ sm: {
125
+ item: string[];
126
+ };
127
+ md: {
128
+ item: string[];
129
+ };
130
+ lg: {
131
+ item: string[];
132
+ };
133
+ clear: {};
134
+ };
99
135
  }, {
100
136
  root: string[];
101
137
  item: string[];
@@ -9,7 +9,7 @@ export const segmentVariants = tv({
9
9
  'cgui:data-[disabled=""]:opacity-50 cgui:data-[disabled=""]:cursor-not-allowed cgui:data-[disabled=""]:pointer-events-none',
10
10
  ],
11
11
  item: [
12
- 'cgui:flex cgui:items-center cgui:justify-center cgui:flex-1',
12
+ 'cgui:flex cgui:items-center cgui:justify-center cgui:min-w-fit',
13
13
  'cgui:font-medium cgui:text-body-2',
14
14
  'cgui:rounded-[inherit]',
15
15
  'cgui:cursor-pointer cgui:overflow-hidden cgui:select-none',
@@ -53,6 +53,18 @@ export const segmentVariants = tv({
53
53
  item: ['cgui:h-11'],
54
54
  },
55
55
  },
56
+ spacingX: {
57
+ sm: {
58
+ item: ['cgui:px-2'],
59
+ },
60
+ md: {
61
+ item: ['cgui:px-4'],
62
+ },
63
+ lg: {
64
+ item: ['cgui:px-6'],
65
+ },
66
+ clear: {},
67
+ },
56
68
  },
57
69
  });
58
70
  export const SegmentStylesContext = new Context(keyWithPrefix('segment-styles'));
@@ -1,5 +1,6 @@
1
1
  import type { PrimitiveButtonAttributes, PrimitiveDivAttributes } from '../../internal/types/html-attributes.js';
2
- import type { WithChildren, WithElementRef, Without } from 'svelte-toolbelt';
2
+ import type { Snippet } from 'svelte';
3
+ import type { WithChild, WithChildren, WithElementRef, Without } from 'svelte-toolbelt';
3
4
  import type { SegmentVariantsProps } from './styles.js';
4
5
  type SegmentRootPropsWithouitHTML = WithElementRef<WithChildren<{
5
6
  value?: string;
@@ -7,8 +8,20 @@ type SegmentRootPropsWithouitHTML = WithElementRef<WithChildren<{
7
8
  disabled?: boolean;
8
9
  } & SegmentVariantsProps>>;
9
10
  export type SegmentRootProps = SegmentRootPropsWithouitHTML & Without<PrimitiveDivAttributes, SegmentRootPropsWithouitHTML>;
10
- type SegmentItemPropsWithoutHTML = WithElementRef<WithChildren<{
11
+ type SegmentItemPropsWithoutHTML = WithElementRef<WithChild<{
11
12
  value: string;
12
13
  }>>;
13
14
  export type SegmentItemProps = SegmentItemPropsWithoutHTML & Without<PrimitiveButtonAttributes, SegmentItemPropsWithoutHTML>;
15
+ export type SegmentItemValue = {
16
+ key: string | number;
17
+ label: string;
18
+ value: string;
19
+ };
20
+ export type SegmentProps = SegmentRootProps & {
21
+ items: SegmentItemValue[];
22
+ item?: Snippet<[{
23
+ item: SegmentItemValue;
24
+ props: Record<string, unknown>;
25
+ }]>;
26
+ };
14
27
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@casinogate/ui",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "svelte": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",