@flightlesslabs/dodo-ui 0.2.0 → 0.3.0

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.
Files changed (64) hide show
  1. package/dist/index.d.ts +6 -0
  2. package/dist/index.js +4 -0
  3. package/dist/stories/Home.mdx +1 -1
  4. package/dist/stories/components/Form/Button/Button.stories.svelte +10 -5
  5. package/dist/stories/components/Form/Button/Button.svelte +213 -208
  6. package/dist/stories/components/Form/Button/Button.svelte.d.ts +4 -1
  7. package/dist/stories/components/Form/Button/Events/Events.stories.svelte +40 -0
  8. package/dist/stories/components/Form/Button/Events/Events.stories.svelte.d.ts +18 -0
  9. package/dist/stories/components/Form/Button/utils/scss/mixins.scss +21 -21
  10. package/dist/stories/components/Form/PasswordInput/Events/Events.stories.svelte +168 -0
  11. package/dist/stories/components/Form/PasswordInput/Events/Events.stories.svelte.d.ts +18 -0
  12. package/dist/stories/components/Form/PasswordInput/PasswordInput.stories.svelte +37 -0
  13. package/dist/stories/components/Form/PasswordInput/PasswordInput.stories.svelte.d.ts +21 -0
  14. package/dist/stories/components/Form/PasswordInput/PasswordInput.svelte +219 -0
  15. package/dist/stories/components/Form/PasswordInput/PasswordInput.svelte.d.ts +59 -0
  16. package/dist/stories/components/Form/PasswordInput/Roundness/Roundness.stories.svelte +20 -0
  17. package/dist/stories/components/Form/{ExampleButton/ExampleButton.stories.svelte.d.ts → PasswordInput/Roundness/Roundness.stories.svelte.d.ts} +3 -4
  18. package/dist/stories/components/Form/PasswordInput/Size/Size.stories.svelte +16 -0
  19. package/dist/stories/components/Form/PasswordInput/Size/Size.stories.svelte.d.ts +26 -0
  20. package/dist/stories/components/Form/PasswordInput/WithIcon/WithIcon.stories.svelte +31 -0
  21. package/dist/stories/components/Form/PasswordInput/WithIcon/WithIcon.stories.svelte.d.ts +26 -0
  22. package/dist/stories/components/Form/TextInput/Events/Events.stories.svelte +148 -0
  23. package/dist/stories/components/Form/TextInput/Events/Events.stories.svelte.d.ts +18 -0
  24. package/dist/stories/components/Form/TextInput/Roundness/Roundness.stories.svelte +21 -0
  25. package/dist/stories/components/Form/TextInput/Roundness/Roundness.stories.svelte.d.ts +26 -0
  26. package/dist/stories/components/Form/TextInput/Size/Size.stories.svelte +17 -0
  27. package/dist/stories/components/Form/TextInput/Size/Size.stories.svelte.d.ts +26 -0
  28. package/dist/stories/components/Form/TextInput/TextInput.stories.svelte +35 -0
  29. package/dist/stories/components/Form/TextInput/TextInput.stories.svelte.d.ts +21 -0
  30. package/dist/stories/components/Form/TextInput/TextInput.svelte +166 -0
  31. package/dist/stories/components/Form/TextInput/TextInput.svelte.d.ts +56 -0
  32. package/dist/stories/components/Form/TextInput/WithIcon/WithIcon.stories.svelte +47 -0
  33. package/dist/stories/components/Form/TextInput/WithIcon/WithIcon.stories.svelte.d.ts +26 -0
  34. package/dist/styles/_components.css +8 -7
  35. package/dist/styles/_minimal-reset.css +3 -0
  36. package/dist/styles/global.css +1 -0
  37. package/package.json +1 -1
  38. package/src/lib/index.ts +13 -0
  39. package/src/lib/stories/components/Form/Button/Button.stories.svelte +10 -5
  40. package/src/lib/stories/components/Form/Button/Button.svelte +32 -22
  41. package/src/lib/stories/components/Form/Button/Events/Events.stories.svelte +42 -0
  42. package/src/lib/stories/components/Form/Button/utils/scss/mixins.scss +21 -21
  43. package/src/lib/stories/components/Form/PasswordInput/Events/Events.stories.svelte +174 -0
  44. package/src/lib/stories/components/Form/PasswordInput/PasswordInput.stories.svelte +41 -0
  45. package/src/lib/stories/components/Form/PasswordInput/PasswordInput.svelte +361 -0
  46. package/src/lib/stories/components/Form/PasswordInput/Roundness/Roundness.stories.svelte +20 -0
  47. package/src/lib/stories/components/Form/PasswordInput/Size/Size.stories.svelte +16 -0
  48. package/src/lib/stories/components/Form/PasswordInput/WithIcon/WithIcon.stories.svelte +31 -0
  49. package/src/lib/stories/components/Form/TextInput/Events/Events.stories.svelte +153 -0
  50. package/src/lib/stories/components/Form/TextInput/Roundness/Roundness.stories.svelte +21 -0
  51. package/src/lib/stories/components/Form/TextInput/Size/Size.stories.svelte +17 -0
  52. package/src/lib/stories/components/Form/TextInput/TextInput.stories.svelte +39 -0
  53. package/src/lib/stories/components/Form/TextInput/TextInput.svelte +293 -0
  54. package/src/lib/stories/components/Form/TextInput/WithIcon/WithIcon.stories.svelte +47 -0
  55. package/src/lib/styles/_components.css +8 -7
  56. package/src/lib/styles/_minimal-reset.css +3 -0
  57. package/src/lib/styles/global.css +1 -0
  58. package/dist/stories/components/Form/ExampleButton/ExampleButton.stories.svelte +0 -30
  59. package/dist/stories/components/Form/ExampleButton/ExampleButton.svelte +0 -14
  60. package/dist/stories/components/Form/ExampleButton/ExampleButton.svelte.d.ts +0 -16
  61. package/dist/stories/components/Form/ExampleButton/button.css +0 -30
  62. package/src/lib/stories/components/Form/ExampleButton/ExampleButton.stories.svelte +0 -30
  63. package/src/lib/stories/components/Form/ExampleButton/ExampleButton.svelte +0 -29
  64. package/src/lib/stories/components/Form/ExampleButton/button.css +0 -30
@@ -4,6 +4,7 @@ export type ButtonLinkTarget = '_self' | '_blank' | '_parent' | '_top' | (string
4
4
  export type ButtonLinkReferrerpolicy = ReferrerPolicy | undefined | null;
5
5
  import type { ComponentRoundness, ComponentRoundnessFull, ComponentSize } from '../../../../types.js';
6
6
  import type { Snippet } from 'svelte';
7
+ import type { MouseEventHandler } from 'svelte/elements';
7
8
  interface ButtonProps {
8
9
  /** Button contents goes here*/
9
10
  children?: Snippet;
@@ -11,6 +12,8 @@ interface ButtonProps {
11
12
  type?: 'button' | 'submit';
12
13
  /** How large should the button be? */
13
14
  size?: ComponentSize;
15
+ /** Full width button? */
16
+ fullWidth?: boolean;
14
17
  /** What color to use? */
15
18
  color?: ButtonColor;
16
19
  /** How round should the border radius be? */
@@ -36,7 +39,7 @@ interface ButtonProps {
36
39
  /** Custom css class*/
37
40
  class?: string;
38
41
  /** The onclick event handler */
39
- onclick?: (e: MouseEvent) => void;
42
+ onclick?: MouseEventHandler<HTMLButtonElement>;
40
43
  /** Turn Button into link */
41
44
  href?: string;
42
45
  /** Link button: download */
@@ -0,0 +1,40 @@
1
+ <script module lang="ts">import { defineMeta } from '@storybook/addon-svelte-csf';
2
+ import { fn } from '@storybook/test';
3
+ import Button from '../Button.svelte';
4
+ import { storyButtonArgTypes } from '../Button.stories.svelte';
5
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
6
+ const { Story } = defineMeta({
7
+ component: Button,
8
+ tags: ['autodocs'],
9
+ argTypes: storyButtonArgTypes,
10
+ args: {
11
+ onclick: fn(),
12
+ },
13
+ });
14
+ </script>
15
+
16
+ <Story
17
+ name="Click"
18
+ args={{
19
+ outline: false,
20
+ disabled: false,
21
+ compact: false,
22
+ onclick: (e: Event) => {
23
+ const target = e.target as HTMLButtonElement;
24
+
25
+ alert('Button Clicked');
26
+ console.log('Button Clicked', target);
27
+ },
28
+ }}
29
+ >
30
+ <Button
31
+ onclick={(e: Event) => {
32
+ const target = e.target as HTMLButtonElement;
33
+
34
+ alert('Button Clicked');
35
+ console.log('Button Clicked', target);
36
+ }}
37
+ >
38
+ Click me!
39
+ </Button>
40
+ </Story>
@@ -0,0 +1,18 @@
1
+ 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
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const Events: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type Events = InstanceType<typeof Events>;
18
+ export default Events;
@@ -3,15 +3,15 @@
3
3
  /// across different interaction states (default, hover, active).
4
4
  /// @param {String} $color-name - The theme color name (e.g., "primary", "safe", etc.)
5
5
  @mixin generate-dodo-ui-button-colors($color-name) {
6
- --dodo-ui-button-outline-#{$color-name}: var(--dodo-color-#{$color-name}-400);
6
+ --dodo-ui-Button-outline-#{$color-name}: var(--dodo-color-#{$color-name}-400);
7
7
 
8
- --dodo-ui-button-text-#{$color-name}-bg: var(--dodo-color-#{$color-name}-100);
9
- --dodo-ui-button-text-#{$color-name}-hover-bg: var(--dodo-color-#{$color-name}-200);
10
- --dodo-ui-button-text-#{$color-name}-active-bg: var(--dodo-color-#{$color-name}-300);
8
+ --dodo-ui-Button-text-#{$color-name}-bg: var(--dodo-color-#{$color-name}-100);
9
+ --dodo-ui-Button-text-#{$color-name}-hover-bg: var(--dodo-color-#{$color-name}-200);
10
+ --dodo-ui-Button-text-#{$color-name}-active-bg: var(--dodo-color-#{$color-name}-300);
11
11
 
12
- --dodo-ui-button-solid-#{$color-name}-bg: var(--dodo-color-#{$color-name}-500);
13
- --dodo-ui-button-solid-#{$color-name}-hover-bg: var(--dodo-color-#{$color-name}-600);
14
- --dodo-ui-button-solid-#{$color-name}-active-bg: var(--dodo-color-#{$color-name}-700);
12
+ --dodo-ui-Button-solid-#{$color-name}-bg: var(--dodo-color-#{$color-name}-500);
13
+ --dodo-ui-Button-solid-#{$color-name}-hover-bg: var(--dodo-color-#{$color-name}-600);
14
+ --dodo-ui-Button-solid-#{$color-name}-active-bg: var(--dodo-color-#{$color-name}-700);
15
15
  }
16
16
 
17
17
  /// Mixin: generate-dodo-ui-button-colors
@@ -19,15 +19,15 @@
19
19
  /// across different interaction states (default, hover, active).
20
20
  /// @param {String} $color-name - The theme color name (e.g., "primary", "safe", etc.)
21
21
  @mixin generate-dodo-ui-button-colors-dark($color-name) {
22
- --dodo-ui-button-outline-#{$color-name}: var(--dodo-color-#{$color-name}-300);
22
+ --dodo-ui-Button-outline-#{$color-name}: var(--dodo-color-#{$color-name}-300);
23
23
 
24
- --dodo-ui-button-text-#{$color-name}-bg: var(--dodo-color-#{$color-name}-50);
25
- --dodo-ui-button-text-#{$color-name}-hover-bg: var(--dodo-color-#{$color-name}-100);
26
- --dodo-ui-button-text-#{$color-name}-active-bg: var(--dodo-color-#{$color-name}-200);
24
+ --dodo-ui-Button-text-#{$color-name}-bg: var(--dodo-color-#{$color-name}-50);
25
+ --dodo-ui-Button-text-#{$color-name}-hover-bg: var(--dodo-color-#{$color-name}-100);
26
+ --dodo-ui-Button-text-#{$color-name}-active-bg: var(--dodo-color-#{$color-name}-200);
27
27
 
28
- --dodo-ui-button-solid-#{$color-name}-bg: var(--dodo-color-#{$color-name}-300);
29
- --dodo-ui-button-solid-#{$color-name}-hover-bg: var(--dodo-color-#{$color-name}-200);
30
- --dodo-ui-button-solid-#{$color-name}-active-bg: var(--dodo-color-#{$color-name}-100);
28
+ --dodo-ui-Button-solid-#{$color-name}-bg: var(--dodo-color-#{$color-name}-300);
29
+ --dodo-ui-Button-solid-#{$color-name}-hover-bg: var(--dodo-color-#{$color-name}-200);
30
+ --dodo-ui-Button-solid-#{$color-name}-active-bg: var(--dodo-color-#{$color-name}-100);
31
31
  }
32
32
 
33
33
  /// Mixin: generate-dodo-ui-button-color
@@ -38,31 +38,31 @@
38
38
  &.variant {
39
39
  &--text {
40
40
  color: var(--dodo-color-#{$theme}-800);
41
- background-color: var(--dodo-ui-button-text-#{$theme}-bg);
41
+ background-color: var(--dodo-ui-Button-text-#{$theme}-bg);
42
42
 
43
43
  &:hover {
44
- background-color: var(--dodo-ui-button-text-#{$theme}-hover-bg);
44
+ background-color: var(--dodo-ui-Button-text-#{$theme}-hover-bg);
45
45
  }
46
46
 
47
47
  &:active {
48
- background-color: var(--dodo-ui-button-text-#{$theme}-active-bg);
48
+ background-color: var(--dodo-ui-Button-text-#{$theme}-active-bg);
49
49
  }
50
50
 
51
51
  &.outline {
52
- border-color: var(--dodo-ui-button-outline-#{$theme});
52
+ border-color: var(--dodo-ui-Button-outline-#{$theme});
53
53
  }
54
54
  }
55
55
 
56
56
  &--solid {
57
57
  color: var(--dodo-color-constant-white);
58
- background-color: var(--dodo-ui-button-solid-#{$theme}-bg);
58
+ background-color: var(--dodo-ui-Button-solid-#{$theme}-bg);
59
59
 
60
60
  &:hover {
61
- background-color: var(--dodo-ui-button-solid-#{$theme}-hover-bg);
61
+ background-color: var(--dodo-ui-Button-solid-#{$theme}-hover-bg);
62
62
  }
63
63
 
64
64
  &:active {
65
- background-color: var(--dodo-ui-button-solid-#{$theme}-active-bg);
65
+ background-color: var(--dodo-ui-Button-solid-#{$theme}-active-bg);
66
66
  }
67
67
  }
68
68
  }
@@ -0,0 +1,168 @@
1
+ <script module lang="ts">import { defineMeta } from '@storybook/addon-svelte-csf';
2
+ import { storyPasswordInputArgTypes } from '../PasswordInput.stories.svelte';
3
+ import PasswordInput, {} from '../PasswordInput.svelte';
4
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
5
+ const { Story } = defineMeta({
6
+ component: PasswordInput,
7
+ tags: ['autodocs'],
8
+ argTypes: storyPasswordInputArgTypes,
9
+ });
10
+ </script>
11
+
12
+ <Story
13
+ name="Input"
14
+ args={{
15
+ oninput: (e: Event) => {
16
+ const target = e.target as HTMLInputElement;
17
+
18
+ console.log('Input Event', target.value);
19
+ },
20
+ }}
21
+ >
22
+ <PasswordInput
23
+ oninput={(e: Event) => {
24
+ const target = e.target as HTMLInputElement;
25
+
26
+ console.log('Input Event', target.value);
27
+ }}
28
+ />
29
+ </Story>
30
+
31
+ <Story
32
+ name="Change"
33
+ args={{
34
+ onchange: (e: Event) => {
35
+ const target = e.target as HTMLInputElement;
36
+
37
+ console.log('onChange Event', target.value);
38
+ },
39
+ }}
40
+ >
41
+ <PasswordInput
42
+ onchange={(e: Event) => {
43
+ const target = e.target as HTMLInputElement;
44
+
45
+ console.log('onchange Event', target.value);
46
+ }}
47
+ />
48
+ </Story>
49
+
50
+ <!-- `e: PasswordInputToggleEvent` -->
51
+ <Story
52
+ name="Toggle"
53
+ args={{
54
+ ontoggle: (e: PasswordInputToggleEvent) => {
55
+ const target = e.event.target as HTMLButtonElement;
56
+
57
+ console.log('ontoggle Event', e, target);
58
+ },
59
+ }}
60
+ >
61
+ <PasswordInput
62
+ ontoggle={(e: PasswordInputToggleEvent) => {
63
+ const target = e.event.target as HTMLButtonElement;
64
+
65
+ console.log('ontoggle Event', e, target);
66
+ }}
67
+ />
68
+ </Story>
69
+
70
+ <!-- `e: TextInputFocusEvent` -->
71
+ <Story
72
+ name="Focus"
73
+ args={{
74
+ onfocus: (e: TextInputFocusEvent) => {
75
+ const target = e.target as HTMLInputElement;
76
+
77
+ console.log('onfocus Event', target);
78
+ },
79
+ }}
80
+ >
81
+ <PasswordInput
82
+ onfocus={(e: TextInputFocusEvent) => {
83
+ const target = e.target as HTMLInputElement;
84
+
85
+ console.log('onfocus Event', target);
86
+ }}
87
+ />
88
+ </Story>
89
+
90
+ <!-- `e: TextInputFocusEvent` -->
91
+ <Story
92
+ name="Blur"
93
+ args={{
94
+ onblur: (e: TextInputFocusEvent) => {
95
+ const target = e.target as HTMLInputElement;
96
+
97
+ console.log('onblur Event', target);
98
+ },
99
+ }}
100
+ >
101
+ <PasswordInput
102
+ onblur={(e: TextInputFocusEvent) => {
103
+ const target = e.target as HTMLInputElement;
104
+
105
+ console.log('onblur Event', target);
106
+ }}
107
+ />
108
+ </Story>
109
+
110
+ <!-- `e: TextInputClipboardEvent` -->
111
+ <Story
112
+ name="Copy"
113
+ args={{
114
+ oncopy: (e: TextInputClipboardEvent) => {
115
+ const target = e.target as HTMLInputElement;
116
+
117
+ console.log('oncopy Event', target);
118
+ },
119
+ }}
120
+ >
121
+ <PasswordInput
122
+ oncopy={(e: TextInputClipboardEvent) => {
123
+ const target = e.target as HTMLInputElement;
124
+
125
+ console.log('oncopy Event', target);
126
+ }}
127
+ />
128
+ </Story>
129
+
130
+ <!-- `e: TextInputClipboardEvent` -->
131
+ <Story
132
+ name="Cut"
133
+ args={{
134
+ oncut: (e: TextInputClipboardEvent) => {
135
+ const target = e.target as HTMLInputElement;
136
+
137
+ console.log('oncut Event', target);
138
+ },
139
+ }}
140
+ >
141
+ <PasswordInput
142
+ oncut={(e: TextInputClipboardEvent) => {
143
+ const target = e.target as HTMLInputElement;
144
+
145
+ console.log('oncut Event', target);
146
+ }}
147
+ />
148
+ </Story>
149
+
150
+ <!-- `e: TextInputClipboardEvent` -->
151
+ <Story
152
+ name="Paste"
153
+ args={{
154
+ onpaste: (e: TextInputClipboardEvent) => {
155
+ const target = e.target as HTMLInputElement;
156
+
157
+ console.log('onpaste Event', target);
158
+ },
159
+ }}
160
+ >
161
+ <PasswordInput
162
+ onpaste={(e: TextInputClipboardEvent) => {
163
+ const target = e.target as HTMLInputElement;
164
+
165
+ console.log('onpaste Event', target);
166
+ }}
167
+ />
168
+ </Story>
@@ -0,0 +1,18 @@
1
+ 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
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const Events: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type Events = InstanceType<typeof Events>;
18
+ export default Events;
@@ -0,0 +1,37 @@
1
+ <script module lang="ts">import { defineMeta } from '@storybook/addon-svelte-csf';
2
+ import PasswordInput from './PasswordInput.svelte';
3
+ export const storyPasswordInputArgTypes = {
4
+ roundness: {
5
+ control: { type: 'select' },
6
+ options: [false, '1x', '2x', '3x'],
7
+ },
8
+ size: {
9
+ control: { type: 'select' },
10
+ options: ['normal', 'small', 'large'],
11
+ },
12
+ };
13
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
14
+ const { Story } = defineMeta({
15
+ component: PasswordInput,
16
+ tags: ['autodocs'],
17
+ argTypes: storyPasswordInputArgTypes,
18
+ args: { value: 'Hello world!' },
19
+ });
20
+ </script>
21
+
22
+ <!-- PasswordInput with default style -->
23
+ <Story name="Default" />
24
+
25
+ <Story name="Placeholder" args={{ value: '', placeholder: 'Type something...' }} />
26
+
27
+ <Story name="No Outline" args={{ outline: false }} />
28
+
29
+ <Story name="Error" args={{ error: true }} />
30
+
31
+ <Story name="Disabled" args={{ disabled: true }} />
32
+
33
+ <!-- Disable password toggle -->
34
+ <Story name="No toggle" args={{ passwordToggle: false }} />
35
+
36
+ <!-- Show Password by default -->
37
+ <Story name="Show Password" args={{ defaultPasswordToggleState: true }} />
@@ -0,0 +1,21 @@
1
+ import PasswordInput from './PasswordInput.svelte';
2
+ import type { StoryBookArgTypes } from '../../../../storybook-types.js';
3
+ export declare const storyPasswordInputArgTypes: StoryBookArgTypes;
4
+ 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> {
5
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
6
+ $$bindings?: Bindings;
7
+ } & Exports;
8
+ (internal: unknown, props: {
9
+ $$events?: Events;
10
+ $$slots?: Slots;
11
+ }): Exports & {
12
+ $set?: any;
13
+ $on?: any;
14
+ };
15
+ z_$$bindings?: Bindings;
16
+ }
17
+ declare const PasswordInput: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
18
+ [evt: string]: CustomEvent<any>;
19
+ }, {}, {}, string>;
20
+ type PasswordInput = InstanceType<typeof PasswordInput>;
21
+ export default PasswordInput;
@@ -0,0 +1,219 @@
1
+ <script lang="ts" module>export {};
2
+ </script>
3
+
4
+ <script lang="ts">import Icon from '@iconify/svelte';
5
+ let { size = 'normal', roundness = '1x', outline = true, name, id, class: className = '', disabled = false, oninput, onchange, onblur, onfocus, onpaste, oncopy, oncut, before, after, passwordToggleIcon, error = false, passwordToggle = true, defaultPasswordToggleState = false, value = $bindable(), placeholder, ontoggle, } = $props();
6
+ let focused = $state(false);
7
+ let toggle = $state(defaultPasswordToggleState);
8
+ function onfocusMod(e) {
9
+ focused = true;
10
+ if (onfocus) {
11
+ onfocus(e);
12
+ }
13
+ }
14
+ function onblurMod(e) {
15
+ focused = false;
16
+ if (onblur) {
17
+ onblur(e);
18
+ }
19
+ }
20
+ function ontoggleMod(e) {
21
+ toggle = !toggle;
22
+ const customEvent = {
23
+ event: e,
24
+ toggle,
25
+ };
26
+ if (ontoggle) {
27
+ ontoggle(customEvent);
28
+ }
29
+ }
30
+ </script>
31
+
32
+ <div
33
+ class:outline
34
+ class:disabled
35
+ class:error
36
+ class:focused
37
+ class:toggle
38
+ class={['dodo-ui-PasswordInput', `size--${size}`, `roundness--${roundness}`, className].join(' ')}
39
+ >
40
+ {#if before}
41
+ <span class="content--before">
42
+ {@render before()}
43
+ </span>
44
+ {/if}
45
+ <input
46
+ type={passwordToggle && toggle ? 'text' : 'password'}
47
+ {name}
48
+ {id}
49
+ {disabled}
50
+ {oninput}
51
+ {onchange}
52
+ onfocus={onfocusMod}
53
+ onblur={onblurMod}
54
+ {onpaste}
55
+ {oncopy}
56
+ {oncut}
57
+ {placeholder}
58
+ bind:value
59
+ />
60
+
61
+ {#if passwordToggle && !disabled}
62
+ <button class="passwordToggle" title="Toggle password" onclick={ontoggleMod} class:toggle>
63
+ {#if passwordToggleIcon}
64
+ {@render passwordToggleIcon()}
65
+ {:else if toggle}
66
+ <Icon icon="mdi:eye-off" width="24" height="24" />
67
+ {:else}
68
+ <Icon icon="mdi:eye" width="24" height="24" />
69
+ {/if}
70
+ </button>
71
+ {/if}
72
+
73
+ {#if after}
74
+ <span class="content--after">
75
+ {@render after()}
76
+ </span>
77
+ {/if}
78
+ </div>
79
+
80
+ <style>:global(:root) {
81
+ --dodo-ui-PasswordInput-border-color: var(--dodo-color-default-500);
82
+ --dodo-ui-PasswordInput-focus-border-color: var(--dodo-color-primary-500);
83
+ --dodo-ui-PasswordInput-error-border-color: var(--dodo-color-danger-500);
84
+ --dodo-ui-PasswordInput-disabled-color: var(--dodo-color-default-400);
85
+ --dodo-ui-PasswordInput-disabled-bg: var(--dodo-color-default-200);
86
+ --dodo-ui-PasswordInput-ToggleButton-hover: var(--dodo-color-primary-700);
87
+ }
88
+
89
+ :global(.dodo-theme--dark) {
90
+ --dodo-ui-PasswordInput-border-color: var(--dodo-color-default-600);
91
+ --dodo-ui-PasswordInput-focus-border-color: var(--dodo-color-primary-600);
92
+ --dodo-ui-PasswordInput-error-border-color: var(--dodo-color-danger-600);
93
+ --dodo-ui-PasswordInput-disabled-bg: var(--dodo-color-default-100);
94
+ --dodo-ui-PasswordInput-disabled-color: var(--dodo-color-default-500);
95
+ --dodo-ui-PasswordInput-ToggleButton-hover: var(--dodo-color-primary-600);
96
+ }
97
+
98
+ .dodo-ui-PasswordInput {
99
+ display: flex;
100
+ overflow: hidden;
101
+ color: var(--dodo-color-default-800);
102
+ transition: all 150ms;
103
+ border: 0;
104
+ }
105
+ .dodo-ui-PasswordInput input {
106
+ flex: 1;
107
+ border: 0;
108
+ outline: 0;
109
+ height: 100%;
110
+ background-color: transparent;
111
+ font-family: inherit;
112
+ color: inherit;
113
+ letter-spacing: 0.3px;
114
+ }
115
+ .dodo-ui-PasswordInput.outline {
116
+ border-style: solid;
117
+ border-width: var(--dodo-ui-element-border-width);
118
+ border-color: var(--dodo-ui-PasswordInput-border-color);
119
+ }
120
+ .dodo-ui-PasswordInput.focused {
121
+ border-color: var(--dodo-ui-PasswordInput-focus-border-color);
122
+ }
123
+ .dodo-ui-PasswordInput.error {
124
+ border-color: var(--dodo-ui-PasswordInput-error-border-color);
125
+ }
126
+ .dodo-ui-PasswordInput.disabled {
127
+ cursor: initial;
128
+ background-color: var(--dodo-ui-PasswordInput-disabled-bg);
129
+ color: var(--dodo-ui-PasswordInput-disabled-color);
130
+ border-color: var(--dodo-ui-PasswordInput-disabled-bg);
131
+ }
132
+ .dodo-ui-PasswordInput .content--after:empty, .dodo-ui-PasswordInput .content--before:empty {
133
+ display: none;
134
+ }
135
+ .dodo-ui-PasswordInput .content--after, .dodo-ui-PasswordInput .content--before {
136
+ display: inline-flex;
137
+ height: 100%;
138
+ align-items: center;
139
+ }
140
+ .dodo-ui-PasswordInput.size--normal {
141
+ height: var(--dodo-ui-element-height-normal);
142
+ }
143
+ .dodo-ui-PasswordInput.size--normal input {
144
+ font-size: 1rem;
145
+ padding: 0 12px;
146
+ }
147
+ .dodo-ui-PasswordInput.size--normal .content--before {
148
+ margin-left: 12px;
149
+ margin-right: -4px;
150
+ }
151
+ .dodo-ui-PasswordInput.size--normal .content--after {
152
+ margin-right: 12px;
153
+ margin-left: -4px;
154
+ }
155
+ .dodo-ui-PasswordInput.size--normal .passwordToggle {
156
+ width: var(--dodo-ui-element-height-normal);
157
+ }
158
+ .dodo-ui-PasswordInput.size--small {
159
+ height: var(--dodo-ui-element-height-small);
160
+ }
161
+ .dodo-ui-PasswordInput.size--small input {
162
+ padding: 0 8px;
163
+ font-size: 0.9rem;
164
+ }
165
+ .dodo-ui-PasswordInput.size--small .content--before {
166
+ margin-left: 8px;
167
+ margin-right: -2px;
168
+ }
169
+ .dodo-ui-PasswordInput.size--small .content--after {
170
+ margin-right: 8px;
171
+ margin-left: -2px;
172
+ }
173
+ .dodo-ui-PasswordInput.size--small .passwordToggle {
174
+ width: var(--dodo-ui-element-height-small);
175
+ }
176
+ .dodo-ui-PasswordInput.size--large {
177
+ height: var(--dodo-ui-element-height-large);
178
+ }
179
+ .dodo-ui-PasswordInput.size--large input {
180
+ font-size: 1.1rem;
181
+ padding: 0 14px;
182
+ }
183
+ .dodo-ui-PasswordInput.size--large .content--before {
184
+ margin-left: 14px;
185
+ margin-right: -4px;
186
+ }
187
+ .dodo-ui-PasswordInput.size--large .content--after {
188
+ margin-right: 14px;
189
+ margin-left: -4px;
190
+ }
191
+ .dodo-ui-PasswordInput.size--large .passwordToggle {
192
+ width: var(--dodo-ui-element-height-large);
193
+ }
194
+ .dodo-ui-PasswordInput.roundness--1x {
195
+ border-radius: var(--dodo-ui-element-roundness-1x);
196
+ }
197
+ .dodo-ui-PasswordInput.roundness--2x {
198
+ border-radius: var(--dodo-ui-element-roundness-2x);
199
+ }
200
+ .dodo-ui-PasswordInput.roundness--3x {
201
+ border-radius: var(--dodo-ui-element-roundness-3x);
202
+ }
203
+ .dodo-ui-PasswordInput .passwordToggle {
204
+ background-color: transparent;
205
+ outline: 0;
206
+ border: 0;
207
+ display: inline-flex;
208
+ justify-content: center;
209
+ align-items: center;
210
+ height: 100%;
211
+ cursor: pointer;
212
+ padding: 0;
213
+ margin-right: 4px;
214
+ color: var(--dodo-color-default-700);
215
+ transition: all 150ms;
216
+ }
217
+ .dodo-ui-PasswordInput .passwordToggle:hover {
218
+ color: var(--dodo-ui-PasswordInput-ToggleButton-hover);
219
+ }</style>