@kkkarsss/ui 1.4.3 → 1.4.4
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.
|
@@ -7,6 +7,9 @@ type TProps = {
|
|
|
7
7
|
onClick?: VoidFunction;
|
|
8
8
|
accLeft?: FC<LucideProps>;
|
|
9
9
|
children: ReactElement<TTypoProps>;
|
|
10
|
+
value?: string | number;
|
|
11
|
+
defaultValue?: string | number;
|
|
12
|
+
onDefaultClick?: VoidFunction;
|
|
10
13
|
};
|
|
11
14
|
export declare const Chip: FC<TProps>;
|
|
12
15
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { animated, config, useSpring } from '@react-spring/web';
|
|
3
|
+
import { X } from 'lucide-react';
|
|
3
4
|
import { Activity, createElement, useState } from 'react';
|
|
4
5
|
import { jc } from '../../../utils';
|
|
5
6
|
const variantMap = {
|
|
@@ -7,11 +8,17 @@ const variantMap = {
|
|
|
7
8
|
accent: 'bg-accent text-accent-foreground',
|
|
8
9
|
secondary: 'bg-transparent text-secondary-foreground border border-secondary-foreground',
|
|
9
10
|
};
|
|
10
|
-
export const Chip = ({ children, onClick, accLeft, variant = 'default' }) => {
|
|
11
|
+
export const Chip = ({ children, onClick, accLeft, variant = 'default', value, defaultValue, onDefaultClick, }) => {
|
|
11
12
|
const [pressed, setPressed] = useState(false);
|
|
12
13
|
const springs = useSpring({
|
|
13
14
|
transform: pressed ? 'scale(0.95)' : 'scale(1)',
|
|
14
15
|
config: config.stiff,
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
+
const isDefaulted = defaultValue !== undefined && value === defaultValue;
|
|
18
|
+
const showReset = defaultValue !== undefined && value !== defaultValue;
|
|
19
|
+
const currentVariant = defaultValue !== undefined ? (isDefaulted ? 'default' : 'accent') : variant;
|
|
20
|
+
return (_jsxs(animated.button, { style: springs, onMouseDown: () => setPressed(true), onMouseUp: () => setPressed(false), onMouseLeave: () => setPressed(false), onClick: onClick, className: jc('flex items-center text-nowrap gap-[5px] w-min px-2 py-1 rounded-2xl outline-none border-none cursor-pointer text-[14px]', variantMap[currentVariant]), children: [_jsx(Activity, { mode: accLeft ? 'visible' : 'hidden', children: accLeft ? createElement(accLeft, { size: 14, color: 'white', strokeWidth: 3 }) : null }), children, _jsx(Activity, { mode: showReset ? 'visible' : 'hidden', children: _jsx(X, { size: 14, color: currentVariant === 'accent' ? 'white' : 'black', strokeWidth: 3, onClick: (e) => {
|
|
21
|
+
e.stopPropagation();
|
|
22
|
+
onDefaultClick?.();
|
|
23
|
+
} }) })] }));
|
|
17
24
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Mail } from 'lucide-react';
|
|
3
|
+
import { useState } from 'react';
|
|
3
4
|
import { Chip } from './chip';
|
|
4
5
|
import { Typo } from '../../information';
|
|
5
6
|
const meta = {
|
|
@@ -40,3 +41,9 @@ export const WithIcon = {
|
|
|
40
41
|
variant: 'accent',
|
|
41
42
|
},
|
|
42
43
|
};
|
|
44
|
+
export const DefaultValue = {
|
|
45
|
+
render: (args) => {
|
|
46
|
+
const [value, setValue] = useState('initial');
|
|
47
|
+
return (_jsx(Chip, { ...args, value: value, defaultValue: "default", onDefaultClick: () => setValue('default'), onClick: () => setValue('modified'), children: _jsx(Typo, { children: value }) }));
|
|
48
|
+
},
|
|
49
|
+
};
|