@cmdniels/uikit 1.0.1 → 1.0.2

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.
@@ -1,3 +1,3 @@
1
1
  import { type ComponentProps } from "react";
2
2
  import InputGroupInput from "../../components/input-group/InputGroupInput";
3
- export default function CopyInput({ disabled, defaultValue, value, onChange, ...props }: ComponentProps<typeof InputGroupInput>): import("react/jsx-runtime").JSX.Element;
3
+ export default function CopyInput({ disabled, defaultValue, value, onChange, children, ...props }: ComponentProps<typeof InputGroupInput>): import("react/jsx-runtime").JSX.Element;
@@ -12,21 +12,34 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { IconCopy } from "@tabler/icons-react";
15
- import { useState, useRef } from "react";
15
+ import { useState, useRef, Children, isValidElement } from "react";
16
16
  import Button from "../../components/button/Button";
17
17
  import InputGroup from "../../components/input-group/InputGroup";
18
18
  import InputGroupAddon from "../../components/input-group/InputGroupAddon";
19
19
  import InputGroupInput from "../../components/input-group/InputGroupInput";
20
20
  export default function CopyInput(_a) {
21
- var { disabled, defaultValue, value, onChange } = _a, props = __rest(_a, ["disabled", "defaultValue", "value", "onChange"]);
21
+ var { disabled, defaultValue, value, onChange, children } = _a, props = __rest(_a, ["disabled", "defaultValue", "value", "onChange", "children"]);
22
22
  const inputRef = useRef(null);
23
23
  const [hasValue, setHasValue] = useState(Boolean(value !== null && value !== void 0 ? value : defaultValue));
24
24
  const handleChange = (e) => {
25
25
  onChange === null || onChange === void 0 ? void 0 : onChange(e);
26
26
  setHasValue(Boolean(e.target.value));
27
27
  };
28
- return (_jsxs(InputGroup, { children: [_jsx(InputGroupInput, Object.assign({ ref: inputRef, disabled: disabled, defaultValue: defaultValue, value: value, onChange: handleChange }, props)), _jsx(InputGroupAddon, { align: "inline-end", children: _jsx(Button, { variant: "link", className: "h-8 px-2", disabled: disabled !== null && disabled !== void 0 ? disabled : !hasValue, onClick: () => {
29
- var _a, _b;
30
- navigator.clipboard.writeText((_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "");
31
- }, children: _jsx(IconCopy, { className: "size-4" }) }) })] }));
28
+ const handleCopy = () => {
29
+ var _a, _b, _c, _d;
30
+ const inputValue = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "";
31
+ const text = (_d = (_c = Children.map(children, (child) => {
32
+ if (isValidElement(child) && child.props.children) {
33
+ const inputGroupText = child.props.children;
34
+ if (isValidElement(inputGroupText) && inputGroupText.props.children) {
35
+ const innerText = inputGroupText.props.children;
36
+ if (typeof innerText === "string" || typeof innerText === "number") {
37
+ return innerText;
38
+ }
39
+ }
40
+ }
41
+ })) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : "";
42
+ navigator.clipboard.writeText(text + inputValue);
43
+ };
44
+ return (_jsxs(InputGroup, { children: [_jsx(InputGroupInput, Object.assign({ ref: inputRef, disabled: disabled, defaultValue: defaultValue, value: value, onChange: handleChange }, props)), _jsx(InputGroupAddon, { align: "inline-end", children: _jsx(Button, { variant: "link", className: "h-8 px-2", disabled: disabled !== null && disabled !== void 0 ? disabled : !hasValue, onClick: handleCopy, children: _jsx(IconCopy, { className: "size-4" }) }) }), children] }));
32
45
  }
@@ -14,5 +14,5 @@ import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import cn from "../../cn";
15
15
  export default function InputGroup(_a) {
16
16
  var { className } = _a, props = __rest(_a, ["className"]);
17
- return (_jsx("div", Object.assign({ "data-slot": "input-group", role: "group", className: cn("group/input-group relative flex h-9 w-full min-w-0 items-center rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-[3px] has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5 [[data-slot=combobox-content]_&]:focus-within:border-inherit [[data-slot=combobox-content]_&]:focus-within:ring-0", className) }, props)));
17
+ return (_jsx("div", Object.assign({ "data-slot": "input-group", role: "group", className: cn("group/input-group relative flex h-9 w-full min-w-0 items-center rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-[3px] has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5", className) }, props)));
18
18
  }
@@ -1,3 +1,3 @@
1
1
  import { type ComponentProps } from "react";
2
2
  import InputGroupInput from "../../components/input-group/InputGroupInput";
3
- export default function LinkInput({ disabled, defaultValue, value, onChange, ...props }: ComponentProps<typeof InputGroupInput>): import("react/jsx-runtime").JSX.Element;
3
+ export default function LinkInput({ disabled, defaultValue, value, onChange, children, ...props }: ComponentProps<typeof InputGroupInput>): import("react/jsx-runtime").JSX.Element;
@@ -12,13 +12,13 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { IconExternalLink } from "@tabler/icons-react";
15
- import { useState, useRef } from "react";
15
+ import { useState, useRef, isValidElement, Children } from "react";
16
16
  import Button from "../../components/button/Button";
17
17
  import InputGroup from "../../components/input-group/InputGroup";
18
18
  import InputGroupAddon from "../../components/input-group/InputGroupAddon";
19
19
  import InputGroupInput from "../../components/input-group/InputGroupInput";
20
20
  export default function LinkInput(_a) {
21
- var { disabled, defaultValue, value, onChange } = _a, props = __rest(_a, ["disabled", "defaultValue", "value", "onChange"]);
21
+ var { disabled, defaultValue, value, onChange, children } = _a, props = __rest(_a, ["disabled", "defaultValue", "value", "onChange", "children"]);
22
22
  const inputRef = useRef(null);
23
23
  const debounceRef = useRef(undefined);
24
24
  const [hasValidValue, setHasValidValue] = useState(/^https?:\/\/.+/.test(String(value !== null && value !== void 0 ? value : defaultValue)));
@@ -32,10 +32,21 @@ export default function LinkInput(_a) {
32
32
  setHasValidValue(/^https?:\/\/.+/.test(e.target.value));
33
33
  }, 300);
34
34
  };
35
- return (_jsxs(InputGroup, { children: [_jsx(InputGroupInput, Object.assign({ ref: inputRef, disabled: disabled, defaultValue: defaultValue, value: value, onChange: handleChange }, props)), _jsx(InputGroupAddon, { align: "inline-end", children: _jsx(Button, { variant: "link", className: "h-8 px-2", disabled: disabled !== null && disabled !== void 0 ? disabled : !hasValidValue, onClick: () => {
36
- var _a, _b;
37
- if ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) {
38
- window.open((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.value, "_blank", "noopener,noreferrer");
39
- }
40
- }, children: _jsx(IconExternalLink, { className: "size-4" }) }) })] }));
35
+ const handleCopy = () => {
36
+ var _a, _b, _c, _d;
37
+ const inputValue = (_b = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "";
38
+ const text = (_d = (_c = Children.map(children, (child) => {
39
+ if (isValidElement(child) && child.props.children) {
40
+ const inputGroupText = child.props.children;
41
+ if (isValidElement(inputGroupText) && inputGroupText.props.children) {
42
+ const innerText = inputGroupText.props.children;
43
+ if (typeof innerText === "string" || typeof innerText === "number") {
44
+ return innerText;
45
+ }
46
+ }
47
+ }
48
+ })) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : "";
49
+ window.open(text + inputValue, "_blank", "noopener,noreferrer");
50
+ };
51
+ return (_jsxs(InputGroup, { children: [_jsx(InputGroupInput, Object.assign({ ref: inputRef, disabled: disabled, defaultValue: defaultValue, value: value, onChange: handleChange }, props)), _jsx(InputGroupAddon, { align: "inline-end", children: _jsx(Button, { variant: "link", className: "h-8 px-2", disabled: disabled !== null && disabled !== void 0 ? disabled : !hasValidValue, onClick: handleCopy, children: _jsx(IconExternalLink, { className: "size-4" }) }) }), children] }));
41
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmdniels/uikit",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",