@rokkit/forms 1.0.0-next.147 → 1.0.0-next.150

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.
@@ -11,6 +11,7 @@ export { default as InputPassword } from "./InputPassword.svelte";
11
11
  export { default as InputRadio } from "./InputRadio.svelte";
12
12
  export { default as InputRange } from "./InputRange.svelte";
13
13
  export { default as InputSelect } from "./InputSelect.svelte";
14
+ export { default as InputSwatch } from "./InputSwatch.svelte";
14
15
  export { default as InputSwitch } from "./InputSwitch.svelte";
15
16
  export { default as InputTel } from "./InputTel.svelte";
16
17
  export { default as InputText } from "./InputText.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/forms",
3
- "version": "1.0.0-next.147",
3
+ "version": "1.0.0-next.150",
4
4
  "description": "Form building components for Rokkit applications",
5
5
  "repository": {
6
6
  "type": "git",
package/src/Input.svelte CHANGED
@@ -17,8 +17,8 @@
17
17
  const extraProps = $derived(type === 'integer' ? { step: '1' } : {})
18
18
  </script>
19
19
 
20
- {#if type === 'checkbox'}
21
- {@const Component = resolveRenderer({ type: 'checkbox' }, allRenderers)}
20
+ {#if type === 'checkbox' || type === 'swatch'}
21
+ {@const Component = resolveRenderer({ type, props: restProps }, allRenderers)}
22
22
  <Component bind:value {onchange} {oninput} {onfocus} {onblur} {...restProps} />
23
23
  {:else}
24
24
  {@const Component = resolveRenderer({ type, props: restProps }, allRenderers)}
@@ -0,0 +1,30 @@
1
+ <script>
2
+ import { Swatch } from '@rokkit/ui'
3
+
4
+ /**
5
+ * @typedef {Object} InputSwatchProps
6
+ * @property {any} value - Selected value (bindable); array when multiple=true
7
+ * @property {Array<Object|string>} [options] - Options array
8
+ * @property {Object} [fields] - Field mapping (label, value, disabled)
9
+ * @property {boolean} [multiple] - Multi-select mode
10
+ * @property {'square'|'circle'} [shape] - Default cell shape
11
+ * @property {'sm'|'md'|'lg'} [size] - Size variant
12
+ * @property {boolean} [disabled] - Disabled state
13
+ * @property {Function} [onchange] - Change callback
14
+ */
15
+
16
+ /** @type {InputSwatchProps & { [key: string]: any }} */
17
+ let {
18
+ value = $bindable(),
19
+ options = [],
20
+ fields,
21
+ multiple = false,
22
+ shape = 'square',
23
+ size = 'md',
24
+ disabled = false,
25
+ onchange,
26
+ ..._rest
27
+ } = $props()
28
+ </script>
29
+
30
+ <Swatch {options} {fields} bind:value {multiple} {shape} {size} {disabled} {onchange} />
@@ -14,6 +14,7 @@ export { default as InputRadio } from './InputRadio.svelte'
14
14
 
15
15
  export { default as InputRange } from './InputRange.svelte'
16
16
  export { default as InputSelect } from './InputSelect.svelte'
17
+ export { default as InputSwatch } from './InputSwatch.svelte'
17
18
  export { default as InputSwitch } from './InputSwitch.svelte'
18
19
  export { default as InputTel } from './InputTel.svelte'
19
20
  export { default as InputText } from './InputText.svelte'
@@ -53,19 +53,17 @@
53
53
  }
54
54
  }
55
55
 
56
+ // Resolve new value from event based on input type
57
+ function resolveValue(event) {
58
+ if (type === 'checkbox' || type === 'radio') return event.target.checked
59
+ if (type === 'number' || type === 'range') return event.target.valueAsNumber
60
+ return event.target.value
61
+ }
62
+
56
63
  // Handle change events
57
64
  function handleChange(event) {
58
- if (type === 'checkbox' || type === 'radio') {
59
- value = event.target.checked
60
- } else if (type === 'number' || type === 'range') {
61
- value = event.target.valueAsNumber
62
- } else {
63
- value = event.target.value
64
- }
65
-
66
- if (onchange) {
67
- onchange(value)
68
- }
65
+ value = resolveValue(event)
66
+ if (onchange) onchange(value)
69
67
  }
70
68
 
71
69
  // Generate unique ID for accessibility
@@ -777,6 +777,7 @@ export class FormBuilder {
777
777
  * @returns {Set<string>}
778
778
  */
779
779
  get dirtyFields() {
780
+ // eslint-disable-next-line svelte/prefer-svelte-reactivity
780
781
  const dirty = new Set()
781
782
  this.#collectDirtyFields(this.#data, this.#initialData, '', dirty)
782
783
  return dirty
@@ -20,6 +20,7 @@ import InputRange from '../input/InputRange.svelte'
20
20
  import InputSelect from '../input/InputSelect.svelte'
21
21
  import InputSwitch from '../input/InputSwitch.svelte'
22
22
  import InputToggle from '../input/InputToggle.svelte'
23
+ import InputSwatch from '../input/InputSwatch.svelte'
23
24
  import InputTel from '../input/InputTel.svelte'
24
25
  import InputText from '../input/InputText.svelte'
25
26
  import InputTextArea from '../input/InputTextArea.svelte'
@@ -54,7 +55,8 @@ export const defaultRenderers = {
54
55
  radio: InputRadio,
55
56
  select: InputSelect,
56
57
  switch: InputSwitch,
57
- toggle: InputToggle
58
+ toggle: InputToggle,
59
+ swatch: InputSwatch
58
60
  }
59
61
 
60
62
  /**