@greghowe79/the-lib 0.7.4 → 0.7.6

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.
@@ -26,11 +26,14 @@ const uploadImage = qwik.$(async (_event, input, currentFile, selectedFile, imag
26
26
  if (selectedFile) selectedFile.value = file.name;
27
27
  }
28
28
  });
29
- const Input = qwik.component$(({ id, type, placeholder, value, error, onValidate$, onInput$, bgLight, currentFile, selectedFile, icon }) => {
29
+ const Input = qwik.component$(({ id, type, placeholder, value, error, onValidate$, onInput$, bgLight, currentFile, selectedFile, icon, prefix }) => {
30
30
  qwik.useStylesScoped$(styles);
31
31
  const internalError = qwik.useSignal(null);
32
32
  const showError = error ?? internalError;
33
33
  const inputHandler = qwik.$(async (_, elem) => {
34
+ if (type === "tel") {
35
+ elem.value = elem.value.replace(/[^0-9]/g, "");
36
+ }
34
37
  if (value) value.value = elem.value;
35
38
  if (onInput$) {
36
39
  await onInput$();
@@ -80,6 +83,35 @@ const Input = qwik.component$(({ id, type, placeholder, value, error, onValidate
80
83
  })
81
84
  ]
82
85
  })
86
+ }) : type === "tel" ? /* @__PURE__ */ jsxRuntime.jsx("label", {
87
+ class: `input-label ${bgLight ? "bg_light" : ""}`,
88
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", {
89
+ class: "input-wrapper",
90
+ children: [
91
+ /* @__PURE__ */ jsxRuntime.jsx("span", {
92
+ class: "input-icon",
93
+ "aria-hidden": "true",
94
+ children: prefix
95
+ }),
96
+ /* @__PURE__ */ jsxRuntime.jsx("input", {
97
+ id,
98
+ type,
99
+ inputMode: "tel",
100
+ pattern: "[0-9]*",
101
+ class: `input ${showError.value ? "error" : ""}`,
102
+ placeholder,
103
+ "bind:value": value,
104
+ onInput$: inputHandler,
105
+ onBlur$: inputHandler,
106
+ onKeyDown$: (e) => {
107
+ const allowed = /[0-9]/;
108
+ if (!allowed.test(e.key) && e.key.length === 1) {
109
+ e.preventDefault();
110
+ }
111
+ }
112
+ })
113
+ ]
114
+ })
83
115
  }) : /* @__PURE__ */ jsxRuntime.jsx("label", {
84
116
  class: `input-label ${bgLight ? "bg_light" : ""}`,
85
117
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -24,11 +24,14 @@ const uploadImage = $(async (_event, input, currentFile, selectedFile, imageUrl)
24
24
  if (selectedFile) selectedFile.value = file.name;
25
25
  }
26
26
  });
27
- const Input = component$(({ id, type, placeholder, value, error, onValidate$, onInput$, bgLight, currentFile, selectedFile, icon }) => {
27
+ const Input = component$(({ id, type, placeholder, value, error, onValidate$, onInput$, bgLight, currentFile, selectedFile, icon, prefix }) => {
28
28
  useStylesScoped$(styles);
29
29
  const internalError = useSignal(null);
30
30
  const showError = error ?? internalError;
31
31
  const inputHandler = $(async (_, elem) => {
32
+ if (type === "tel") {
33
+ elem.value = elem.value.replace(/[^0-9]/g, "");
34
+ }
32
35
  if (value) value.value = elem.value;
33
36
  if (onInput$) {
34
37
  await onInput$();
@@ -78,6 +81,35 @@ const Input = component$(({ id, type, placeholder, value, error, onValidate$, on
78
81
  })
79
82
  ]
80
83
  })
84
+ }) : type === "tel" ? /* @__PURE__ */ jsx("label", {
85
+ class: `input-label ${bgLight ? "bg_light" : ""}`,
86
+ children: /* @__PURE__ */ jsxs("div", {
87
+ class: "input-wrapper",
88
+ children: [
89
+ /* @__PURE__ */ jsx("span", {
90
+ class: "input-icon",
91
+ "aria-hidden": "true",
92
+ children: prefix
93
+ }),
94
+ /* @__PURE__ */ jsx("input", {
95
+ id,
96
+ type,
97
+ inputMode: "tel",
98
+ pattern: "[0-9]*",
99
+ class: `input ${showError.value ? "error" : ""}`,
100
+ placeholder,
101
+ "bind:value": value,
102
+ onInput$: inputHandler,
103
+ onBlur$: inputHandler,
104
+ onKeyDown$: (e) => {
105
+ const allowed = /[0-9]/;
106
+ if (!allowed.test(e.key) && e.key.length === 1) {
107
+ e.preventDefault();
108
+ }
109
+ }
110
+ })
111
+ ]
112
+ })
81
113
  }) : /* @__PURE__ */ jsx("label", {
82
114
  class: `input-label ${bgLight ? "bg_light" : ""}`,
83
115
  children: /* @__PURE__ */ jsxs("div", {
@@ -13,6 +13,7 @@ export interface InputProps {
13
13
  currentFile?: Signal<any>;
14
14
  selectedFile?: Signal<string>;
15
15
  icon?: JSXOutput | Component<unknown>;
16
+ prefix?: Signal<string>;
16
17
  }
17
18
  export declare const displayLocalImage: QRL<(file: File, imageUrl?: Signal<string>) => void>;
18
19
  export declare const uploadImage: QRL<(_event: Event, input: HTMLInputElement, currentFile?: Signal<any>, selectedFile?: Signal<string>, imageUrl?: Signal<string>) => Promise<void>>;
@@ -6,4 +6,5 @@ type Story = StoryObj<InputProps>;
6
6
  export declare const Email: Story;
7
7
  export declare const InputLightBackground: Story;
8
8
  export declare const InputWithIcon: Story;
9
+ export declare const PhoneInput: Story;
9
10
  export declare const FileUpload: Story;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greghowe79/the-lib",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "Collection of fast components for Qwik",
5
5
  "main": "./lib/index.qwik.mjs",
6
6
  "qwik": "./lib/index.qwik.mjs",