sveltacular 1.0.23 → 1.0.25

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.
@@ -3,26 +3,57 @@
3
3
  import Button from '../button/button.svelte';
4
4
  import type { ButtonVariant } from '../../types';
5
5
 
6
- export interface ButtonOpts {
7
- type?: 'submit' | 'button';
6
+ export type AdditionalButton = {
7
+ type?: 'button' | 'submit' | 'reset';
8
8
  variant?: ButtonVariant;
9
9
  text: string;
10
- onClick?: () => void;
11
- }
10
+ onClick?: ((e?: Event) => void) | undefined;
11
+ disabled?: boolean;
12
+ };
12
13
 
13
14
  let {
14
15
  children,
15
- buttons = [
16
- {
17
- type: 'submit',
18
- variant: 'primary',
19
- text: 'Save'
20
- }
21
- ]
16
+ disabled = false,
17
+ onCancel = undefined,
18
+ onSubmit = undefined,
19
+ cancelText = 'Cancel',
20
+ cancelVariant = 'secondary',
21
+ submitText = 'Submit',
22
+ submitVariant = 'primary',
23
+ additionalButtons = []
22
24
  }: {
23
25
  children?: Snippet;
24
- buttons?: ButtonOpts[];
26
+ disabled?: boolean;
27
+ onCancel?: (() => void) | undefined;
28
+ cancelText?: string;
29
+ cancelVariant?: ButtonVariant;
30
+ submitText?: string;
31
+ submitVariant?: ButtonVariant;
32
+ onSubmit?: (() => void) | undefined;
33
+ additionalButtons?: AdditionalButton[];
25
34
  } = $props();
35
+
36
+ const buttons = $derived(
37
+ [
38
+ onCancel
39
+ ? {
40
+ type: 'button' as const,
41
+ variant: cancelVariant,
42
+ text: cancelText,
43
+ onClick: onCancel,
44
+ disabled
45
+ }
46
+ : undefined,
47
+ ...additionalButtons.map((btn) => ({ ...btn, disabled: btn.disabled || disabled })),
48
+ {
49
+ type: 'submit' as const,
50
+ variant: submitVariant,
51
+ text: submitText,
52
+ onClick: onSubmit,
53
+ disabled
54
+ }
55
+ ].filter(Boolean) as AdditionalButton[]
56
+ );
26
57
  </script>
27
58
 
28
59
  <div class="form-actions">
@@ -34,9 +65,10 @@
34
65
  <div class="buttons">
35
66
  {#each buttons as button}
36
67
  <Button
37
- type={button.type ?? 'submit'}
68
+ type={button.type ?? 'button'}
38
69
  variant={button.variant ?? 'secondary'}
39
- onClick={button.onClick ?? undefined}
70
+ onClick={button.onClick}
71
+ disabled={button.disabled}
40
72
  >
41
73
  {button.text}
42
74
  </Button>
@@ -50,9 +82,9 @@
50
82
  .form-actions {
51
83
  display: flex;
52
84
  flex-direction: row;
53
- align-items: center;
85
+ align-items: flex-end; /* Align both sections to bottom */
54
86
  justify-content: space-between;
55
- gap: var(--spacing-md);
87
+ gap: var(--spacing-xl);
56
88
  /* Vertical spacing - separate form from actions and actions from content below */
57
89
  margin-top: var(--spacing-xl);
58
90
  margin-bottom: var(--spacing-lg);
@@ -62,18 +94,18 @@
62
94
  }
63
95
  .form-actions .content {
64
96
  display: flex;
65
- flex-direction: row;
66
- align-items: center;
67
- gap: var(--spacing-sm);
68
- flex: 0 1 auto; /* Don't grow, can shrink, auto basis */
97
+ flex-direction: column;
98
+ align-items: flex-start; /* Align content to left */
99
+ gap: var(--spacing-md);
100
+ flex: 1;
69
101
  }
70
102
  .form-actions .buttons {
71
103
  display: flex;
72
104
  flex-direction: row;
73
105
  align-items: center;
106
+ justify-content: flex-end; /* Align buttons to right */
74
107
  gap: var(--spacing-sm);
75
- flex: 0 0 auto; /* Don't grow, don't shrink, auto basis */
76
- margin-left: auto; /* Push to the right */
108
+ flex: 1;
77
109
  }
78
110
  .form-actions {
79
111
  /* Responsive: Stack on mobile */
@@ -81,16 +113,13 @@
81
113
  @media (max-width: 479.98px) {
82
114
  .form-actions {
83
115
  flex-direction: column;
84
- align-items: stretch;
116
+ align-items: center;
85
117
  gap: var(--spacing-md);
86
118
  }
87
119
  .form-actions .content,
88
120
  .form-actions .buttons {
89
121
  width: 100%;
90
- justify-content: flex-start;
91
- }
92
- .form-actions .buttons {
93
- margin-left: 0;
94
- justify-content: flex-end;
122
+ align-items: center;
123
+ justify-content: center;
95
124
  }
96
125
  }</style>
@@ -1,14 +1,22 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { ButtonVariant } from '../../types';
3
- export interface ButtonOpts {
4
- type?: 'submit' | 'button';
3
+ export type AdditionalButton = {
4
+ type?: 'button' | 'submit' | 'reset';
5
5
  variant?: ButtonVariant;
6
6
  text: string;
7
- onClick?: () => void;
8
- }
7
+ onClick?: ((e?: Event) => void) | undefined;
8
+ disabled?: boolean;
9
+ };
9
10
  type $$ComponentProps = {
10
11
  children?: Snippet;
11
- buttons?: ButtonOpts[];
12
+ disabled?: boolean;
13
+ onCancel?: (() => void) | undefined;
14
+ cancelText?: string;
15
+ cancelVariant?: ButtonVariant;
16
+ submitText?: string;
17
+ submitVariant?: ButtonVariant;
18
+ onSubmit?: (() => void) | undefined;
19
+ additionalButtons?: AdditionalButton[];
12
20
  };
13
21
  declare const FormActions: import("svelte").Component<$$ComponentProps, {}, "">;
14
22
  type FormActions = ReturnType<typeof FormActions>;
@@ -21,10 +21,12 @@ export * from './list-box/index.js';
21
21
  export * from './phone-box/index.js';
22
22
  export * from './radio-group/index.js';
23
23
  export { default as Form } from './form.svelte';
24
+ export { default as FormActions } from './form-actions/form-actions.svelte';
24
25
  export { default as FormField } from './form-field/form-field.svelte';
25
26
  export { default as FormFooter } from './form-footer.svelte';
26
27
  export { default as FormHeader } from './form-header.svelte';
27
28
  export { default as FormLabel } from './form-label/form-label.svelte';
28
29
  export { default as FormSection } from './form-section/form-section.svelte';
29
30
  export { default as FormRow } from './form-row/form-row.svelte';
31
+ export type { AdditionalButton } from './form-actions/form-actions.svelte';
30
32
  export * from './validation.js';
@@ -24,6 +24,7 @@ export * from './phone-box/index.js';
24
24
  export * from './radio-group/index.js';
25
25
  // Form structure components
26
26
  export { default as Form } from './form.svelte';
27
+ export { default as FormActions } from './form-actions/form-actions.svelte';
27
28
  export { default as FormField } from './form-field/form-field.svelte';
28
29
  export { default as FormFooter } from './form-footer.svelte';
29
30
  export { default as FormHeader } from './form-header.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveltacular",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "A Svelte component library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",