y200subcontrols 0.0.24 → 0.0.26

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.
package/README.md CHANGED
@@ -1,58 +1,6 @@
1
- # create-svelte
1
+ UI Library using sveltekit and tailwindcss
2
2
 
3
- Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
3
+ In your tailwind.config.js file add the following to content
4
4
 
5
- Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
5
+ './node_modules/y200subcontrols/**/*.{html,js,svelte,ts}'
6
6
 
7
- ## Creating a project
8
-
9
- If you're seeing this, you've probably already done this step. Congrats!
10
-
11
- ```bash
12
- # create a new project in the current directory
13
- npm create svelte@latest
14
-
15
- # create a new project in my-app
16
- npm create svelte@latest my-app
17
- ```
18
-
19
- ## Developing
20
-
21
- Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
22
-
23
- ```bash
24
- npm run dev
25
-
26
- # or start the server and open the app in a new browser tab
27
- npm run dev -- --open
28
- ```
29
-
30
- Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
31
-
32
- ## Building
33
-
34
- To build your library:
35
-
36
- ```bash
37
- npm run package
38
- ```
39
-
40
- To create a production version of your showcase app:
41
-
42
- ```bash
43
- npm run build
44
- ```
45
-
46
- You can preview the production build with `npm run preview`.
47
-
48
- > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
49
-
50
- ## Publishing
51
-
52
- Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
53
-
54
- To publish your library to [npm](https://www.npmjs.com):
55
-
56
- ```bash
57
- npm publish
58
- ```
@@ -1,9 +1,10 @@
1
1
  import { SvelteComponent } from "svelte";
2
+ import type { Size } from './types.js';
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  type?: "submit" | "reset" | "button";
5
6
  buttonStyle?: "red" | "dark" | "indigo" | "teal" | "blue";
6
- buttonSize?: "sm" | "md" | "lg";
7
+ buttonSize?: Size;
7
8
  disabled?: boolean;
8
9
  customCss?: string;
9
10
  isLoading?: boolean;
@@ -0,0 +1,134 @@
1
+ <script>import { onMount, createEventDispatcher } from "svelte";
2
+ export let size = "lg";
3
+ export let labelText = void 0;
4
+ export let id = void 0;
5
+ export let readonly = false;
6
+ export let required = false;
7
+ export let value = void 0;
8
+ export let name = void 0;
9
+ export let placeholder = void 0;
10
+ export let validationText = "This field is required";
11
+ export let autocomplete = "off";
12
+ export let input = void 0;
13
+ export let autoApplyCss = false;
14
+ export let customCss = "";
15
+ export let visible = true;
16
+ export let numeric = false;
17
+ export let allowZero = false;
18
+ export let disabled = false;
19
+ const dispatch = createEventDispatcher();
20
+ export let isValid = true;
21
+ let inputContainer;
22
+ function validateElement(event) {
23
+ if (input.dataset.validated !== "true") {
24
+ return;
25
+ }
26
+ isValid = input.checkValidity();
27
+ if (input.type === "number") {
28
+ if (!allowZero && value === 0 && required) {
29
+ isValid = false;
30
+ }
31
+ }
32
+ dispatch("validated", isValid);
33
+ }
34
+ onMount(() => {
35
+ if (id === void 0) {
36
+ let r = (Math.random() + 1).toString(36).substring(2);
37
+ id = `input${r}`;
38
+ }
39
+ let elem = inputContainer.querySelector("input");
40
+ if (elem) {
41
+ elem.dataset.requiresValidation = "true";
42
+ input = elem;
43
+ elem.addEventListener("change", validateElement);
44
+ elem.addEventListener("validate--custom", validateElement);
45
+ if (id) {
46
+ elem.id = id;
47
+ }
48
+ let _input = elem;
49
+ if (_input) {
50
+ _input.name = name ?? "";
51
+ _input.placeholder = placeholder ?? "";
52
+ }
53
+ if (autoApplyCss) {
54
+ elem.className = `border peer block w-full py-1 px-2 rounded-md shadow-sm bg-white text-neutral-900
55
+ focus:outline-none focus:ring read-only:bg-neutral-100
56
+ placeholder:text-sm placeholder:font-thin
57
+ dark:bg-slate-900 dark:text-neutral-100
58
+ ${!isValid ? "border-pink-600 dark:border-pink-500 focus:ring-pink-600/20 dark:focus:ring-pink-600/40" : "dark:border-slate-600 border-slate-300 focus:ring-blue-500/20 dark:focus:ring-blue-500/30"} ${customCss}`;
59
+ }
60
+ }
61
+ if (numeric && input) {
62
+ input.type = "number";
63
+ }
64
+ });
65
+ </script>
66
+
67
+ <div class={visible ? '' : 'hidden'}>
68
+ {#if labelText}
69
+ <label
70
+ for={id}
71
+ class="inline-block mb-1 text-slate-600 dark:text-neutral-200 font-thin text-lg"
72
+ >
73
+ {labelText}
74
+ {#if required}
75
+ *
76
+ {/if}
77
+ </label>
78
+ {/if}
79
+ <div bind:this={inputContainer}>
80
+ <slot>
81
+ <input
82
+ bind:this={input}
83
+ {disabled}
84
+ {id}
85
+ type="text"
86
+ {required}
87
+ {autocomplete}
88
+ class="border peer block w-full rounded shadow-sm bg-white text-neutral-900
89
+ {size === 'sm' ? 'py-1 px-2 text-sm' : ''}
90
+ {size === 'md' ? 'py-1.5 px-2 text-base' : ''}
91
+ {size === 'lg' ? 'py-2 px-2 text-lg' : ''}
92
+ focus:outline-none focus:ring
93
+ read-only:bg-neutral-100
94
+ dark:read-only:bg-neutral-800
95
+ placeholder:text-sm placeholder:font-thin
96
+ dark:bg-slate-900 dark:text-neutral-100 {numeric ? 'hide-browser-appearance' : ''}
97
+ {!isValid
98
+ ? 'border-pink-600 dark:border-pink-500 focus:ring-pink-600/20 dark:focus:ring-pink-600/40'
99
+ : 'dark:border-slate-600 border-slate-300 focus:ring-teal-500/20 dark:focus:ring-teal-500/30'}
100
+ {customCss}"
101
+ bind:value
102
+ {placeholder}
103
+ {name}
104
+ on:change
105
+ on:keydown
106
+ on:keyup
107
+ {readonly}
108
+ step={numeric ? 'any' : undefined}
109
+ />
110
+ </slot>
111
+ </div>
112
+
113
+ {#if validationText && !isValid}
114
+ <div class="text-xs text-pink-600 dark:text-pink-500 my-1">
115
+ {validationText}
116
+ </div>
117
+ {/if}
118
+ </div>
119
+
120
+ <style>
121
+ .hide-browser-appearance {
122
+ /* -moz-appearance: textfield; */
123
+ -webkit-appearance: none;
124
+ -moz-appearance: none;
125
+ appearance: none;
126
+ }
127
+
128
+ .hide-browser-appearance::-webkit-outer-spin-button,
129
+ .hide-browser-appearance::-webkit-inner-spin-button {
130
+ /* -webkit-appearance: none; */
131
+ -webkit-appearance: none;
132
+ appearance: none;
133
+ }
134
+ </style>
@@ -0,0 +1,43 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { Size } from './types.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ size?: Size;
6
+ labelText?: string | undefined;
7
+ id?: string | undefined;
8
+ readonly?: boolean;
9
+ required?: boolean;
10
+ value?: string | number | undefined;
11
+ name?: string | undefined;
12
+ placeholder?: string | undefined;
13
+ validationText?: string | undefined;
14
+ autocomplete?: string | undefined;
15
+ input?: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | any | undefined;
16
+ autoApplyCss?: boolean;
17
+ customCss?: string;
18
+ visible?: boolean;
19
+ numeric?: boolean;
20
+ allowZero?: boolean;
21
+ disabled?: boolean;
22
+ isValid?: boolean;
23
+ };
24
+ events: {
25
+ change: Event;
26
+ keydown: KeyboardEvent;
27
+ keyup: KeyboardEvent;
28
+ validated: CustomEvent<any>;
29
+ } & {
30
+ [evt: string]: CustomEvent<any>;
31
+ };
32
+ slots: {
33
+ default: {};
34
+ };
35
+ exports?: {} | undefined;
36
+ bindings?: string | undefined;
37
+ };
38
+ export type LabeledFormInputProps = typeof __propDef.props;
39
+ export type LabeledFormInputEvents = typeof __propDef.events;
40
+ export type LabeledFormInputSlots = typeof __propDef.slots;
41
+ export default class LabeledFormInput extends SvelteComponent<LabeledFormInputProps, LabeledFormInputEvents, LabeledFormInputSlots> {
42
+ }
43
+ export {};
@@ -0,0 +1,83 @@
1
+ <script>import { onMount } from "svelte";
2
+ import LabeledFormInput from "./LabeledFormInput.svelte";
3
+ export let size = "lg";
4
+ export let labelText = void 0;
5
+ export let id = void 0;
6
+ export let readonly = false;
7
+ export let required = true;
8
+ export let value = void 0;
9
+ export let name = void 0;
10
+ export let placeholder = void 0;
11
+ export let validationText = void 0;
12
+ export let customCss = "";
13
+ export let customValidation = void 0;
14
+ let input;
15
+ let isValid = true;
16
+ let inputType = "password";
17
+ function handleValidated(event) {
18
+ console.log(event.detail);
19
+ if (customValidation) {
20
+ isValid = event.detail && customValidation();
21
+ } else {
22
+ isValid = event.detail;
23
+ }
24
+ }
25
+ function toggleInputType() {
26
+ inputType = inputType === "password" ? "text" : "password";
27
+ input.type = inputType;
28
+ input.focus();
29
+ }
30
+ onMount(() => {
31
+ if (id === void 0) {
32
+ let r = (Math.random() + 1).toString(36).substring(2);
33
+ id = `password-input${r}`;
34
+ }
35
+ });
36
+ </script>
37
+
38
+ <LabeledFormInput
39
+ {labelText}
40
+ {id}
41
+ {validationText}
42
+ bind:isValid
43
+ {name}
44
+ {required}
45
+ {placeholder}
46
+ on:validated={handleValidated}
47
+ >
48
+ <div class="relative group">
49
+ <input
50
+ type="password"
51
+ bind:this={input}
52
+ class="border peer block w-full rounded shadow-sm bg-white text-neutral-900
53
+ {size === 'sm' ? 'py-1 px-2 text-sm' : ''}
54
+ {size === 'md' ? 'py-1.5 px-2 text-base' : ''}
55
+ {size === 'lg' ? 'py-2 px-2 text-lg' : ''}
56
+ focus:outline-none focus:ring
57
+ read-only:bg-neutral-100
58
+ dark:read-only:bg-neutral-800
59
+ placeholder:text-sm placeholder:font-thin
60
+ dark:bg-slate-900 dark:text-neutral-100
61
+ {!isValid
62
+ ? 'border-pink-600 dark:border-pink-500 focus:ring-pink-600/20 dark:focus:ring-pink-600/40'
63
+ : 'dark:border-slate-600 border-slate-300 focus:ring-teal-500/20 dark:focus:ring-teal-500/30'}
64
+ {customCss}"
65
+ {placeholder}
66
+ {id}
67
+ {name}
68
+ {readonly}
69
+ {required}
70
+ bind:value
71
+ on:change
72
+ />
73
+
74
+ <button
75
+ type="button"
76
+ class="absolute top-0 bottom-0 right-0 w-8 px-1
77
+ text-slate-500 hover:text-teal-600 active:text-teal-700 focus:outline-none"
78
+ on:click={toggleInputType}
79
+ >
80
+ <i class="bi {inputType === 'password' ? 'bi-eye-fill' : 'bi-eye-slash-fill'}" />
81
+ </button>
82
+ </div>
83
+ </LabeledFormInput>
@@ -0,0 +1,31 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { Size } from './types.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ size?: Size;
6
+ labelText?: string | undefined;
7
+ id?: string | undefined;
8
+ readonly?: boolean;
9
+ required?: boolean;
10
+ value?: string | number | undefined;
11
+ name?: string | undefined;
12
+ placeholder?: string | undefined;
13
+ validationText?: string | undefined;
14
+ customCss?: string;
15
+ customValidation?: (() => Boolean) | undefined;
16
+ };
17
+ events: {
18
+ change: Event;
19
+ } & {
20
+ [evt: string]: CustomEvent<any>;
21
+ };
22
+ slots: {};
23
+ exports?: {} | undefined;
24
+ bindings?: string | undefined;
25
+ };
26
+ export type LabeledPasswordInputProps = typeof __propDef.props;
27
+ export type LabeledPasswordInputEvents = typeof __propDef.events;
28
+ export type LabeledPasswordInputSlots = typeof __propDef.slots;
29
+ export default class LabeledPasswordInput extends SvelteComponent<LabeledPasswordInputProps, LabeledPasswordInputEvents, LabeledPasswordInputSlots> {
30
+ }
31
+ export {};
@@ -0,0 +1,24 @@
1
+ <script>export let checked = false;
2
+ export let label = "";
3
+ export let id = void 0;
4
+ export let name = void 0;
5
+ </script>
6
+
7
+ <label class="flex cursor-pointer">
8
+ <input type="checkbox" bind:checked class="hidden peer" {id} {name} />
9
+ <div
10
+ class=" rounded-full h-5 w-10 flex my-auto bg-slate-300
11
+ peer-checked:bg-teal-600 transition-all duration-300"
12
+ >
13
+ <div
14
+ class="w-5 h-5 rounded-full my-auto border border-slate-400 {!checked
15
+ ? 'bg-slate-400 translate-x-0'
16
+ : ' translate-x-5 bg-slate-100 '} transition-all ease-in-out duration-300
17
+ "
18
+ />
19
+ </div>
20
+
21
+ <span class="text-slate-500 my-auto mx-2 text-lg font-thin">
22
+ {label}
23
+ </span>
24
+ </label>
@@ -0,0 +1,21 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ checked?: boolean;
5
+ label?: string;
6
+ id?: string | undefined;
7
+ name?: string | undefined;
8
+ };
9
+ events: {
10
+ [evt: string]: CustomEvent<any>;
11
+ };
12
+ slots: {};
13
+ exports?: {} | undefined;
14
+ bindings?: string | undefined;
15
+ };
16
+ export type ToggleButtonProps = typeof __propDef.props;
17
+ export type ToggleButtonEvents = typeof __propDef.events;
18
+ export type ToggleButtonSlots = typeof __propDef.slots;
19
+ export default class ToggleButton extends SvelteComponent<ToggleButtonProps, ToggleButtonEvents, ToggleButtonSlots> {
20
+ }
21
+ export {};
@@ -0,0 +1 @@
1
+ export type Size = 'sm' | 'md' | 'lg';
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -3,4 +3,7 @@ import Button from "./components/Button.svelte";
3
3
  import Card from "./components/Card.svelte";
4
4
  import CardHeader from "./components/CardHeader.svelte";
5
5
  import Form from "./components/Form.svelte";
6
- export { Button, LoadingIndicator, Card, CardHeader, Form };
6
+ import ToggleButton from "./components/ToggleButton.svelte";
7
+ import LabeledFormInput from "./components/LabeledFormInput.svelte";
8
+ import LabeledPasswordInput from "./components/LabeledPasswordInput.svelte";
9
+ export { Button, LoadingIndicator, Card, CardHeader, Form, ToggleButton, LabeledFormInput, LabeledPasswordInput };
package/dist/index.js CHANGED
@@ -4,4 +4,7 @@ import Button from "./components/Button.svelte";
4
4
  import Card from "./components/Card.svelte";
5
5
  import CardHeader from "./components/CardHeader.svelte";
6
6
  import Form from "./components/Form.svelte";
7
- export { Button, LoadingIndicator, Card, CardHeader, Form };
7
+ import ToggleButton from "./components/ToggleButton.svelte";
8
+ import LabeledFormInput from "./components/LabeledFormInput.svelte";
9
+ import LabeledPasswordInput from "./components/LabeledPasswordInput.svelte";
10
+ export { Button, LoadingIndicator, Card, CardHeader, Form, ToggleButton, LabeledFormInput, LabeledPasswordInput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "y200subcontrols",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",