@noxlovette/material 0.1.0 → 0.1.2

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.
@@ -13,7 +13,6 @@ on screen until confirmed, dismissed, or a required action has been taken.
13
13
  import { dialogue } from './theme.js';
14
14
  import type { DialogueProps } from './types.js';
15
15
  import { Dialog } from 'bits-ui';
16
- import clsx from 'clsx';
17
16
  import { enterExit } from '../../../animation/enterExit.js';
18
17
  import { easeEmphasized, easeEmphasizedDecel } from '../../../animation/easing.js';
19
18
  import { Button } from '../../buttons/index.js';
@@ -33,7 +32,6 @@ on screen until confirmed, dismissed, or a required action has been taken.
33
32
  children,
34
33
  disabled = false,
35
34
  class: className,
36
- toggle = () => {},
37
35
  contentProps,
38
36
  onconfirm,
39
37
  ...rootRest
@@ -43,14 +41,7 @@ on screen until confirmed, dismissed, or a required action has been taken.
43
41
  $derived(dialogue());
44
42
  </script>
45
43
 
46
- <Dialog.Root
47
- bind:open
48
- {...rootRest}
49
- onOpenChange={(v) => {
50
- if (!v) toggle?.();
51
- rootRest.onOpenChange?.(v);
52
- }}
53
- >
44
+ <Dialog.Root bind:open {...rootRest}>
54
45
  <Dialog.Portal disabled={portalDisabled}>
55
46
  <Dialog.Overlay forceMount>
56
47
  {#snippet child({ props, open })}
@@ -73,7 +64,7 @@ on screen until confirmed, dismissed, or a required action has been taken.
73
64
  method="POST"
74
65
  action={confirmAction}
75
66
  use:enhance
76
- onsubmit={(e) => {
67
+ onsubmit={(e: any) => {
77
68
  if (onconfirm) {
78
69
  e.preventDefault();
79
70
  onconfirm();
@@ -9,58 +9,57 @@ Checkboxes let users select one or more items from a list, or turn an item on or
9
9
  import { checkbox } from './theme.js';
10
10
  import type { CheckboxProps } from './types.js';
11
11
  import { Layer } from '../../../utils/index.js';
12
- import { Checkbox } from 'bits-ui';
12
+ import { Checkbox, Label, useId } from 'bits-ui';
13
13
 
14
14
  let {
15
- label,
16
- supportingText,
15
+ labelText,
16
+ labelRef,
17
+ id = useId(),
18
+ ref,
17
19
  indeterminate = $bindable(false),
18
20
  checked = $bindable(false),
19
21
  disabled = false,
20
22
  error = false,
21
- align = 'start',
22
23
  class: className,
23
24
  ...restProps
24
25
  }: CheckboxProps = $props();
25
26
 
26
27
  const state = $derived(indeterminate ? 'indeterminate' : checked ? 'checked' : 'unchecked');
27
- const cls = $derived(checkbox({ state, error, align, disabled }));
28
+ const cls = $derived(checkbox({ state, error, disabled }));
28
29
  </script>
29
30
 
30
- <Checkbox.Root
31
- bind:checked
32
- bind:indeterminate
33
- {disabled}
34
- class={cls.root({ class: clsx(className) })}
35
- {...restProps}
36
- >
37
- {#snippet children({ checked, indeterminate })}
38
- <div class={cls.container()}>
39
- <div class={cls.control()}>
40
- <Layer />
41
- <div class={cls.box()}></div>
42
- </div>
43
- <span class={cls.indeterminateIcon()}></span>
44
- <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class={cls.checkIcon()}>
45
- <path
46
- d="M 4.83 13.41 L 9 17.585 L 19.59 7"
47
- fill="none"
48
- stroke="currentColor"
49
- stroke-width="2"
50
- stroke-linecap="round"
51
- stroke-linejoin="round"
52
- />
53
- </svg>
54
- </div>
55
- {#if label || supportingText}
56
- <div class="flex flex-col gap-1 text-left">
57
- {#if label}
58
- <span class={cls.label()}>{label}</span>
59
- {/if}
60
- {#if supportingText}
61
- <span class={cls.supporting()}>{supportingText}</span>
31
+ <div class="flex cursor-pointer items-center space-x-3">
32
+ <Checkbox.Root
33
+ bind:checked
34
+ bind:indeterminate
35
+ {ref}
36
+ {disabled}
37
+ {id}
38
+ class={cls.root({ class: clsx(className) })}
39
+ {...restProps}
40
+ >
41
+ {#snippet children({ checked, indeterminate })}
42
+ <div class={cls.container()}>
43
+ <div class={cls.control()}>
44
+ <Layer />
45
+ <div class={cls.box()}></div>
46
+ </div>
47
+ {#if indeterminate}
48
+ <span class={cls.indeterminateIcon()}></span>
49
+ {:else if checked}
50
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class={cls.checkIcon()}>
51
+ <path
52
+ d="M 4.83 13.41 L 9 17.585 L 19.59 7"
53
+ fill="none"
54
+ stroke="currentColor"
55
+ stroke-width="2"
56
+ stroke-linecap="round"
57
+ stroke-linejoin="round"
58
+ />
59
+ </svg>
62
60
  {/if}
63
61
  </div>
64
- {/if}
65
- {/snippet}
66
- </Checkbox.Root>
62
+ {/snippet}
63
+ </Checkbox.Root>
64
+ <Label.Root for={id} ref={labelRef} class={cls.label()}>{labelText}</Label.Root>
65
+ </div>
@@ -44,7 +44,6 @@ export declare const checkbox: import("tailwind-variants").TVReturnType<{
44
44
  checkIcon: string;
45
45
  indeterminateIcon: string;
46
46
  label: string;
47
- supporting: string;
48
47
  }, undefined, {
49
48
  state: {
50
49
  unchecked: {};
@@ -90,7 +89,6 @@ export declare const checkbox: import("tailwind-variants").TVReturnType<{
90
89
  checkIcon: string;
91
90
  indeterminateIcon: string;
92
91
  label: string;
93
- supporting: string;
94
92
  }, import("tailwind-variants").TVReturnType<{
95
93
  state: {
96
94
  unchecked: {};
@@ -136,6 +134,5 @@ export declare const checkbox: import("tailwind-variants").TVReturnType<{
136
134
  checkIcon: string;
137
135
  indeterminateIcon: string;
138
136
  label: string;
139
- supporting: string;
140
137
  }, undefined, unknown, unknown, undefined>>;
141
138
  export type CheckboxM3Variants = VariantProps<typeof checkbox>;
@@ -1,14 +1,13 @@
1
1
  import { tv } from 'tailwind-variants';
2
2
  export const checkbox = tv({
3
3
  slots: {
4
- root: 'inline-flex min-h-10 select-none items-start gap-3 text-md-sys-color-on-surface min-h-4.5',
4
+ root: 'inline-flex min-h-10 select-none items-start gap-3 text-md-sys-color-on-surface min-h-4.5 cursor-pointer',
5
5
  container: 'relative inline-flex size-[18px] shrink-0',
6
6
  control: 'layer-container absolute -inset-[11px] rounded-full text-md-sys-color-on-surface-variant state-layer before:rounded-full peer-focus-visible:outline peer-focus-visible:outline-3 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-md-sys-color-secondary',
7
7
  box: 'absolute inset-[11px] rounded-[4px] border-2 border-current bg-md-sys-color-surface',
8
8
  checkIcon: 'pointer-events-none absolute inset-0 m-auto size-5 text-md-sys-color-on-primary opacity-0 scale-75',
9
9
  indeterminateIcon: 'pointer-events-none absolute inset-0 m-auto block h-0.5 w-3 rounded-full bg-md-sys-color-on-primary opacity-0 scale-75',
10
- label: 'md-sys-typescale-body-large leading-5 text-md-sys-color-on-surface',
11
- supporting: 'md-sys-typescale-body-medium text-md-sys-color-on-surface-variant'
10
+ label: 'md-sys-typescale-body-large leading-5 text-md-sys-color-on-surface cursor-pointer'
12
11
  },
13
12
  variants: {
14
13
  state: {
@@ -1,39 +1,8 @@
1
- import type { CheckboxRootProps } from 'bits-ui';
2
- import type { CheckboxM3Variants } from './theme.js';
3
- export type CheckboxProps = CheckboxM3Variants & Omit<CheckboxRootProps, 'children' | 'checked' | 'indeterminate'> & {
4
- /**
5
- * The text label for the checkbox.
6
- */
7
- label?: string;
8
- /**
9
- * Supporting text displayed below the label.
10
- */
11
- supportingText?: string;
12
- /**
13
- * Whether the checkbox is in an indeterminate state.
14
- * @bindable
15
- */
16
- indeterminate?: boolean;
17
- /**
18
- * The value associated with the checkbox.
19
- */
20
- value?: string;
21
- /**
22
- * Whether the checkbox is checked.
23
- * @bindable
24
- */
25
- checked?: boolean;
26
- /**
27
- * Whether the checkbox is disabled.
28
- */
1
+ import type { Checkbox, WithoutChildrenOrChild } from 'bits-ui';
2
+ export type CheckboxProps = WithoutChildrenOrChild<Checkbox.RootProps> & {
3
+ labelText: string;
4
+ labelRef?: HTMLLabelElement;
5
+ } & {
29
6
  disabled?: boolean;
30
- /**
31
- * Whether the checkbox is in an error state.
32
- */
33
7
  error?: boolean;
34
- /**
35
- * Vertical alignment of the checkbox relative to its label.
36
- * @default 'start'
37
- */
38
- align?: 'start' | 'center';
39
8
  };
@@ -11,6 +11,7 @@ Text fields allow users to enter and edit text.
11
11
  import { Icon } from '../../../utils/index.js';
12
12
  import { textfield } from './theme.js';
13
13
  import type { TextfieldProps } from './types.js';
14
+ import { useId } from 'bits-ui';
14
15
 
15
16
  let {
16
17
  value = $bindable(),
@@ -19,7 +20,7 @@ Text fields allow users to enter and edit text.
19
20
  trailingIconProps,
20
21
  placeholder = '',
21
22
  label,
22
- id,
23
+ id = useId(),
23
24
  class: className,
24
25
  characterLimit,
25
26
  disabled = false,
@@ -32,6 +33,7 @@ Text fields allow users to enter and edit text.
32
33
  }: TextfieldProps = $props();
33
34
 
34
35
  const cls = $derived(textfield({ disabled, error }));
36
+
35
37
  const inputProps = $derived({
36
38
  id,
37
39
  class: cls.input(),
@@ -16,11 +16,11 @@ export type TextfieldProps = TextFieldVariants & Omit<HTMLInputAttributes, 'chil
16
16
  */
17
17
  label: string;
18
18
  /**
19
- * The ID for the input element.
19
+ * The ID for the input element. Auto-generated but can be replaced
20
20
  */
21
- id: string;
21
+ id?: string;
22
22
  /**
23
- * The placeholder text for the input element.
23
+ * The placeholder text for the input element. Not used in M3
24
24
  */
25
25
  placeholder?: '';
26
26
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noxlovette/material",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {