@streamscloud/kit 0.9.16 → 0.9.18

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.
@@ -0,0 +1,3 @@
1
+ import type { ArrayValidation } from './types';
2
+ import * as yup from 'yup';
3
+ export declare const arrayValidationSchema: <TItem = unknown>(rules: ArrayValidation) => yup.ArraySchema<TItem[] | undefined, yup.AnyObject, undefined, "">;
@@ -0,0 +1,20 @@
1
+ import { ValidationLocalization } from './validation-localization';
2
+ import * as yup from 'yup';
3
+ export const arrayValidationSchema = (rules) => {
4
+ const msg = new ValidationLocalization();
5
+ const minItems = rules.minItems > 0 ? rules.minItems : 0;
6
+ const maxItems = rules.maxItems !== null && rules.maxItems >= 0 && rules.maxItems >= minItems ? rules.maxItems : undefined;
7
+ let schema = yup.array();
8
+ if (maxItems !== undefined) {
9
+ schema = schema.max(maxItems, msg.maxItems(maxItems));
10
+ }
11
+ if (minItems === 1) {
12
+ return schema.min(1, msg.required);
13
+ }
14
+ else if (minItems > 1) {
15
+ return schema.min(minItems, msg.minItems(minItems));
16
+ }
17
+ else {
18
+ return schema;
19
+ }
20
+ };
@@ -1,5 +1,6 @@
1
- export type { TextValidation, TextWithFormatValidation, NumberValidation, MinNumberValidation } from './types';
1
+ export type { TextValidation, TextWithFormatValidation, NumberValidation, MinNumberValidation, ArrayValidation } from './types';
2
2
  export { emailValidationSchema, nullableEmailValidationSchema } from './email-validation';
3
3
  export { textValidationSchema, formattedTextValidationSchema } from './text-validations';
4
4
  export { handleValidationSchema } from './handle-validations';
5
5
  export { numberValidationSchema, minNumberValidationSchema } from './number-validations';
6
+ export { arrayValidationSchema } from './array-validations';
@@ -2,3 +2,4 @@ export { emailValidationSchema, nullableEmailValidationSchema } from './email-va
2
2
  export { textValidationSchema, formattedTextValidationSchema } from './text-validations';
3
3
  export { handleValidationSchema } from './handle-validations';
4
4
  export { numberValidationSchema, minNumberValidationSchema } from './number-validations';
5
+ export { arrayValidationSchema } from './array-validations';
@@ -17,3 +17,7 @@ export type MinNumberValidation = {
17
17
  minValue: number | null;
18
18
  minExclusive: boolean;
19
19
  };
20
+ export type ArrayValidation = {
21
+ minItems: number;
22
+ maxItems: number | null;
23
+ };
@@ -5,5 +5,7 @@ export declare class ValidationLocalization {
5
5
  get maxLength(): (length: number) => string;
6
6
  get min(): (val: number) => string;
7
7
  get max(): (val: number) => string;
8
+ get minItems(): (count: number) => string;
9
+ get maxItems(): (count: number) => string;
8
10
  get badFormat(): string;
9
11
  }
@@ -18,6 +18,12 @@ export class ValidationLocalization {
18
18
  get max() {
19
19
  return loc.max[AppLocale.current];
20
20
  }
21
+ get minItems() {
22
+ return loc.minItems[AppLocale.current];
23
+ }
24
+ get maxItems() {
25
+ return loc.maxItems[AppLocale.current];
26
+ }
21
27
  get badFormat() {
22
28
  return loc.badFormat[AppLocale.current];
23
29
  }
@@ -47,6 +53,14 @@ const loc = {
47
53
  en: (val) => `Must be at most ${val}`,
48
54
  no: (val) => `Kan ikke være mer enn ${val}`
49
55
  },
56
+ minItems: {
57
+ en: (count) => `Must contain at least ${count} items`,
58
+ no: (count) => `Må inneholde minst ${count} elementer`
59
+ },
60
+ maxItems: {
61
+ en: (count) => `Must contain at most ${count} item${count === 1 ? '' : 's'}`,
62
+ no: (count) => `Kan ikke inneholde mer enn ${count} element${count === 1 ? '' : 'er'}`
63
+ },
50
64
  badFormat: {
51
65
  en: 'Invalid format',
52
66
  no: 'Ugyldig format'
@@ -1,16 +1,16 @@
1
1
  <script lang="ts">import { default as Button } from '../button/cmp.button.svelte';
2
- let { type = 'button', disabled = false, variant = 'primary', icon, on, children } = $props();
2
+ let { type = 'button', disabled = false, loading = false, variant = 'primary', icon, on, children } = $props();
3
3
  </script>
4
4
 
5
5
  <div class="dialog-button">
6
- <Button type={type} disabled={disabled} variant={variant} icon={icon} on={on}>
6
+ <Button type={type} disabled={disabled} loading={loading} variant={variant} icon={icon} on={on}>
7
7
  {@render children()}
8
8
  </Button>
9
9
  </div>
10
10
 
11
11
  <!--
12
12
  @component
13
- DialogButton — action button for a dialog footer with a minimum width preset. Defaults to the `primary` variant. Wraps `<Button>` and exposes the same callback / disabled / type / icon contract.
13
+ DialogButton — action button for a dialog footer with a minimum width preset. Defaults to the `primary` variant. Wraps `<Button>` and exposes the same callback / disabled / loading / type / icon contract.
14
14
 
15
15
  ### CSS Custom Properties
16
16
  | Property | Description | Default |
@@ -5,6 +5,8 @@ type Props = {
5
5
  /** @default 'button' */
6
6
  type?: 'button' | 'submit' | 'reset';
7
7
  disabled?: boolean;
8
+ /** Renders a spinner in place of the icon and blocks clicks. Passed through to Button. @default false */
9
+ loading?: boolean;
8
10
  /** Button color variant @default 'primary' */
9
11
  variant?: ButtonVariant;
10
12
  /** Leading icon — passed through to Button. */
@@ -15,7 +17,7 @@ type Props = {
15
17
  children: Snippet;
16
18
  };
17
19
  /**
18
- * DialogButton — action button for a dialog footer with a minimum width preset. Defaults to the `primary` variant. Wraps `<Button>` and exposes the same callback / disabled / type / icon contract.
20
+ * DialogButton — action button for a dialog footer with a minimum width preset. Defaults to the `primary` variant. Wraps `<Button>` and exposes the same callback / disabled / loading / type / icon contract.
19
21
  *
20
22
  * ### CSS Custom Properties
21
23
  * | Property | Description | Default |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.9.16",
3
+ "version": "0.9.18",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",