@ourtrip/ui 1.0.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.
- package/dist/components/accordion.js +19 -0
- package/dist/components/alert.js +36 -0
- package/dist/components/badge.js +47 -0
- package/dist/components/breadcrumbs.js +22 -0
- package/dist/components/button.js +155 -0
- package/dist/components/card.js +29 -0
- package/dist/components/checkbox.js +24 -0
- package/dist/components/collapse.js +16 -0
- package/dist/components/divider.js +38 -0
- package/dist/components/input.js +58 -0
- package/dist/components/modal.js +10 -0
- package/dist/components/phone.js +53 -0
- package/dist/components/popover.js +35 -0
- package/dist/components/radio.js +38 -0
- package/dist/components/range.js +19 -0
- package/dist/components/select.js +84 -0
- package/dist/components/sheet.js +82 -0
- package/dist/components/stars.js +10 -0
- package/dist/components/step-marker.js +18 -0
- package/dist/components/switch.js +15 -0
- package/dist/components/tag.js +16 -0
- package/dist/components/tooltip.js +9 -0
- package/dist/index.js +22 -0
- package/dist/types/components/accordion.d.ts +7 -0
- package/dist/types/components/alert.d.ts +10 -0
- package/dist/types/components/badge.d.ts +12 -0
- package/dist/types/components/breadcrumbs.d.ts +11 -0
- package/dist/types/components/button.d.ts +19 -0
- package/dist/types/components/card.d.ts +6 -0
- package/dist/types/components/checkbox.d.ts +11 -0
- package/dist/types/components/collapse.d.ts +15 -0
- package/dist/types/components/divider.d.ts +8 -0
- package/dist/types/components/input.d.ts +14 -0
- package/dist/types/components/modal.d.ts +10 -0
- package/dist/types/components/phone.d.ts +18 -0
- package/dist/types/components/popover.d.ts +6 -0
- package/dist/types/components/radio.d.ts +8 -0
- package/dist/types/components/range.d.ts +10 -0
- package/dist/types/components/select.d.ts +13 -0
- package/dist/types/components/sheet.d.ts +25 -0
- package/dist/types/components/stars.d.ts +6 -0
- package/dist/types/components/step-marker.d.ts +11 -0
- package/dist/types/components/switch.d.ts +9 -0
- package/dist/types/components/tag.d.ts +11 -0
- package/dist/types/components/tooltip.d.ts +8 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/utils/classes.d.ts +1 -0
- package/dist/types/utils/validation.d.ts +12 -0
- package/dist/utils/classes.js +7 -0
- package/dist/utils/validation.js +128 -0
- package/ourtrip-ui-1.0.0.tgz +0 -0
- package/package.json +47 -0
- package/src/components/accordion.tsx +52 -0
- package/src/components/alert.tsx +56 -0
- package/src/components/badge.tsx +84 -0
- package/src/components/breadcrumbs.tsx +48 -0
- package/src/components/button.tsx +187 -0
- package/src/components/card.tsx +23 -0
- package/src/components/checkbox.tsx +70 -0
- package/src/components/collapse.tsx +56 -0
- package/src/components/divider.tsx +28 -0
- package/src/components/input.tsx +105 -0
- package/src/components/modal.tsx +40 -0
- package/src/components/phone.tsx +104 -0
- package/src/components/popover.tsx +31 -0
- package/src/components/radio.tsx +44 -0
- package/src/components/range.tsx +54 -0
- package/src/components/select.tsx +160 -0
- package/src/components/sheet.tsx +140 -0
- package/src/components/stars.tsx +30 -0
- package/src/components/step-marker.tsx +49 -0
- package/src/components/switch.tsx +42 -0
- package/src/components/tag.tsx +52 -0
- package/src/components/tooltip.tsx +30 -0
- package/src/index.tsx +22 -0
- package/src/utils/classes.ts +2 -0
- package/src/utils/validation.ts +164 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { FC, ReactNode, useState } from 'react';
|
|
4
|
+
import { CaretDown, CaretUp } from '@phosphor-icons/react';
|
|
5
|
+
|
|
6
|
+
type TToggleType = 'bottom' | 'right';
|
|
7
|
+
type IToggleTextType = {
|
|
8
|
+
open: string;
|
|
9
|
+
close: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
interface ICollapseProps {
|
|
13
|
+
title: string;
|
|
14
|
+
content: ReactNode;
|
|
15
|
+
showPreview?: boolean;
|
|
16
|
+
toggleText?: IToggleTextType;
|
|
17
|
+
togglePosition?: TToggleType;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const Collapse: FC<ICollapseProps> = ({
|
|
21
|
+
title,
|
|
22
|
+
content,
|
|
23
|
+
showPreview = false,
|
|
24
|
+
togglePosition = 'right',
|
|
25
|
+
toggleText
|
|
26
|
+
}) => {
|
|
27
|
+
const [open, setOpen] = useState(false);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div
|
|
31
|
+
className={`relative flex items-start ${
|
|
32
|
+
togglePosition === 'right' ? 'flex-row' : 'flex-col'
|
|
33
|
+
} gap-3`}
|
|
34
|
+
onClick={() => setOpen(prev => !prev)}
|
|
35
|
+
>
|
|
36
|
+
<div className='mt-1'>
|
|
37
|
+
<h3 className='text-sm text-primary-900'>{title}</h3>
|
|
38
|
+
<div
|
|
39
|
+
className={`overflow-hidden transition-max-height duration-300 ease-in-out ${
|
|
40
|
+
open ? 'max-h-[1000px]' : showPreview ? 'max-h-12' : 'max-h-0'
|
|
41
|
+
}`}
|
|
42
|
+
>
|
|
43
|
+
<p className='mt-1 text-gray-500'>{content}</p>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
<div className='flex items-center gap-2'>
|
|
47
|
+
{toggleText && <span>{open ? toggleText.close : toggleText.open}</span>}
|
|
48
|
+
<div className='w-7 h-7 rounded-full bg-gray-100 flex items-center justify-center'>
|
|
49
|
+
{open ? <CaretUp size={18} /> : <CaretDown size={18} />}
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default Collapse;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { HTMLAttributes } from 'react';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
|
|
6
|
+
interface IDivider extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
orientation?: 'horizontal' | 'vertical';
|
|
8
|
+
fullHeight?: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Divider = ({
|
|
13
|
+
orientation = 'vertical',
|
|
14
|
+
fullHeight,
|
|
15
|
+
className,
|
|
16
|
+
...props
|
|
17
|
+
}: IDivider) => {
|
|
18
|
+
const dividerClass = classNames({
|
|
19
|
+
'w-px h-10 bg-gray-200': orientation === 'vertical' && !fullHeight,
|
|
20
|
+
'w-full h-px bg-gray-200': orientation === 'horizontal',
|
|
21
|
+
'w-px h-full bg-gray-200': orientation === 'vertical' && fullHeight,
|
|
22
|
+
[className as string]: className
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return <div {...props} className={dividerClass} />;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default Divider;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-param-reassign */
|
|
4
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
5
|
+
import React, {
|
|
6
|
+
DetailedHTMLProps,
|
|
7
|
+
InputHTMLAttributes,
|
|
8
|
+
forwardRef,
|
|
9
|
+
useRef
|
|
10
|
+
} from 'react';
|
|
11
|
+
|
|
12
|
+
interface IInput
|
|
13
|
+
extends DetailedHTMLProps<
|
|
14
|
+
InputHTMLAttributes<HTMLInputElement>,
|
|
15
|
+
HTMLInputElement
|
|
16
|
+
> {
|
|
17
|
+
label?: string;
|
|
18
|
+
dense?: boolean;
|
|
19
|
+
floating?: boolean;
|
|
20
|
+
border?: boolean;
|
|
21
|
+
color?: 'white' | 'gray';
|
|
22
|
+
error?: string;
|
|
23
|
+
focus?: Function;
|
|
24
|
+
mask?: Function;
|
|
25
|
+
hasInitialValue?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const Input = forwardRef(
|
|
29
|
+
(
|
|
30
|
+
{
|
|
31
|
+
id,
|
|
32
|
+
label,
|
|
33
|
+
placeholder,
|
|
34
|
+
color = 'white',
|
|
35
|
+
dense,
|
|
36
|
+
floating,
|
|
37
|
+
border,
|
|
38
|
+
onChange,
|
|
39
|
+
onFocus,
|
|
40
|
+
onBlur,
|
|
41
|
+
focus,
|
|
42
|
+
error,
|
|
43
|
+
disabled,
|
|
44
|
+
...props
|
|
45
|
+
}: IInput,
|
|
46
|
+
ref: any
|
|
47
|
+
) => {
|
|
48
|
+
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
aria-labelledby={id}
|
|
53
|
+
onClick={() => inputRef.current?.focus()}
|
|
54
|
+
className={`flex flex-col w-full ${props.className}`}
|
|
55
|
+
>
|
|
56
|
+
<div
|
|
57
|
+
onClick={() => {
|
|
58
|
+
if (ref?.current) {
|
|
59
|
+
ref.current?.focus();
|
|
60
|
+
} else {
|
|
61
|
+
focus?.();
|
|
62
|
+
}
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
{label && (
|
|
66
|
+
<label htmlFor={id} className='mb-2 text-sm text-gray-500'>
|
|
67
|
+
{label}
|
|
68
|
+
</label>
|
|
69
|
+
)}
|
|
70
|
+
<input
|
|
71
|
+
id={id}
|
|
72
|
+
ref={e => {
|
|
73
|
+
if (typeof ref === 'function') ref(e);
|
|
74
|
+
else if (ref && typeof ref === 'object') ref.current = e;
|
|
75
|
+
inputRef.current = e;
|
|
76
|
+
}}
|
|
77
|
+
placeholder={placeholder}
|
|
78
|
+
autoComplete='off'
|
|
79
|
+
{...props}
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
onChange={event => {
|
|
82
|
+
onChange?.(event);
|
|
83
|
+
}}
|
|
84
|
+
onFocus={event => {
|
|
85
|
+
onFocus?.(event);
|
|
86
|
+
}}
|
|
87
|
+
onBlur={e => {
|
|
88
|
+
onBlur?.(e);
|
|
89
|
+
}}
|
|
90
|
+
className={`${
|
|
91
|
+
color === 'white'
|
|
92
|
+
? 'bg-white disabled:bg-white'
|
|
93
|
+
: 'bg-gray-100 disabled:bg-gray-100'
|
|
94
|
+
} w-full rounded-button h-[50px] px-4 disabled:cursor-not-allowed placeholder-gray-500 text-primary-900 ${
|
|
95
|
+
props.className
|
|
96
|
+
}`}
|
|
97
|
+
/>
|
|
98
|
+
</div>
|
|
99
|
+
{error && <span className='text-sm text-red-600'>{error}</span>}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
export default Input;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { FC, ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
interface IModalProps {
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
showCloseButton?: boolean;
|
|
9
|
+
onClose?: Function;
|
|
10
|
+
closeOnClickOutside?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const Modal: FC<IModalProps> = ({
|
|
14
|
+
isOpen,
|
|
15
|
+
children,
|
|
16
|
+
onClose,
|
|
17
|
+
showCloseButton = false
|
|
18
|
+
}) => {
|
|
19
|
+
|
|
20
|
+
return isOpen ? (
|
|
21
|
+
<div className='fixed top-0 left-0 w-full h-full bg-black/50 flex justify-center items-center'>
|
|
22
|
+
<div
|
|
23
|
+
className='bg-white rounded-default shadow-lg min-w-[350px] relative'
|
|
24
|
+
>
|
|
25
|
+
{showCloseButton ? (
|
|
26
|
+
<button
|
|
27
|
+
type='button'
|
|
28
|
+
className='absolute top-[10px] right-[10px] cursor-pointer'
|
|
29
|
+
onClick={() => onClose?.()}
|
|
30
|
+
>
|
|
31
|
+
Fechar
|
|
32
|
+
</button>
|
|
33
|
+
) : null}
|
|
34
|
+
<div className='modal-content'>{children}</div>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
) : null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default Modal;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import Input from './input';
|
|
5
|
+
import { isValidDDD, isValidPhoneNumber } from '../utils/validation';
|
|
6
|
+
import {
|
|
7
|
+
FieldErrors,
|
|
8
|
+
FieldValues,
|
|
9
|
+
Path,
|
|
10
|
+
UseFormSetFocus
|
|
11
|
+
} from 'react-hook-form';
|
|
12
|
+
|
|
13
|
+
interface IPhoneInputProps<T extends FieldValues> {
|
|
14
|
+
t: any;
|
|
15
|
+
DDI?: string;
|
|
16
|
+
phoneDDIKey: Path<T>;
|
|
17
|
+
phoneAreaCodeKey: Path<T>;
|
|
18
|
+
phoneNumberKey: Path<T>;
|
|
19
|
+
registerWithMask: any;
|
|
20
|
+
setFocus: UseFormSetFocus<T>;
|
|
21
|
+
errors: FieldErrors<T>;
|
|
22
|
+
ddiClassName?: string;
|
|
23
|
+
areaCodeClassName?: string;
|
|
24
|
+
phoneClassName?: string;
|
|
25
|
+
requiredMessage?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const PhoneInput = <T extends FieldValues>({
|
|
29
|
+
t,
|
|
30
|
+
DDI,
|
|
31
|
+
phoneDDIKey,
|
|
32
|
+
phoneAreaCodeKey,
|
|
33
|
+
phoneNumberKey,
|
|
34
|
+
registerWithMask,
|
|
35
|
+
setFocus,
|
|
36
|
+
errors,
|
|
37
|
+
ddiClassName,
|
|
38
|
+
areaCodeClassName,
|
|
39
|
+
phoneClassName,
|
|
40
|
+
requiredMessage
|
|
41
|
+
}: IPhoneInputProps<T>) => {
|
|
42
|
+
const host = typeof window !== 'undefined' ? window.location.host : '';
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className='w-full flex flex-col gap-1'>
|
|
46
|
+
<div className='flex flex-col md:flex-row gap-0.5'>
|
|
47
|
+
<Input
|
|
48
|
+
className={`flex-2 rounded-b-none md:rounded-r-none md:rounded-l-button ${ddiClassName}`}
|
|
49
|
+
placeholder={t('fieldsLabels.ddi')}
|
|
50
|
+
{...registerWithMask(phoneDDIKey, ['+9', '+99', '+999'], {
|
|
51
|
+
value: DDI,
|
|
52
|
+
required: requiredMessage
|
|
53
|
+
})}
|
|
54
|
+
defaultValue={host?.includes('.br') ? '+55' : ''}
|
|
55
|
+
color='gray'
|
|
56
|
+
/>
|
|
57
|
+
<Input
|
|
58
|
+
className={`flex-2 rounded-none ${areaCodeClassName}`}
|
|
59
|
+
placeholder={t('fieldsLabels.areaCode')}
|
|
60
|
+
{...registerWithMask(phoneAreaCodeKey, DDI === '+55' ? '(99)' : '', {
|
|
61
|
+
required: requiredMessage,
|
|
62
|
+
validate: (value: any) =>
|
|
63
|
+
DDI === '+55'
|
|
64
|
+
? isValidDDD(value)
|
|
65
|
+
: true || t('validations.invalidPhoneAreaCode'),
|
|
66
|
+
oncomplete: () => {
|
|
67
|
+
if (DDI === '+55') {
|
|
68
|
+
setFocus(phoneNumberKey);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
})}
|
|
72
|
+
color='gray'
|
|
73
|
+
/>
|
|
74
|
+
<Input
|
|
75
|
+
className={`flex-5 rounded-t-none md:rounded-l-none md:rounded-r-button ${phoneClassName}`}
|
|
76
|
+
placeholder={t('fieldsLabels.number')}
|
|
77
|
+
{...registerWithMask(
|
|
78
|
+
phoneNumberKey,
|
|
79
|
+
DDI === '+55' ? '99999-9999' : '',
|
|
80
|
+
{
|
|
81
|
+
required: requiredMessage,
|
|
82
|
+
validate: (value: any) =>
|
|
83
|
+
DDI === '+55'
|
|
84
|
+
? isValidPhoneNumber(value)
|
|
85
|
+
: true || t('validations.invalidPhoneNumber')
|
|
86
|
+
}
|
|
87
|
+
)}
|
|
88
|
+
color='gray'
|
|
89
|
+
/>
|
|
90
|
+
</div>
|
|
91
|
+
{((errors?.phone as any)?.ddi?.message ||
|
|
92
|
+
(errors?.phone as any)?.areaCode?.message ||
|
|
93
|
+
(errors?.phone as any)?.number?.message) && (
|
|
94
|
+
<span className='text-red-600 text-sm'>
|
|
95
|
+
{(errors?.phone as any)?.ddi?.message ||
|
|
96
|
+
(errors?.phone as any)?.areaCode?.message ||
|
|
97
|
+
(errors?.phone as any)?.number?.message}
|
|
98
|
+
</span>
|
|
99
|
+
)}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export default PhoneInput;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
5
|
+
|
|
6
|
+
import { cn } from '../utils/classes';
|
|
7
|
+
|
|
8
|
+
const Popover = PopoverPrimitive.Root;
|
|
9
|
+
|
|
10
|
+
const PopoverTrigger = PopoverPrimitive.Trigger;
|
|
11
|
+
|
|
12
|
+
const PopoverContent = React.forwardRef<
|
|
13
|
+
React.ElementRef<typeof PopoverPrimitive.Content>,
|
|
14
|
+
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
|
15
|
+
>(({ className, align = 'center', sideOffset = 4, ...props }, ref) => (
|
|
16
|
+
<PopoverPrimitive.Portal>
|
|
17
|
+
<PopoverPrimitive.Content
|
|
18
|
+
ref={ref}
|
|
19
|
+
align={align}
|
|
20
|
+
sideOffset={sideOffset}
|
|
21
|
+
className={cn(
|
|
22
|
+
'z-50 w-72 rounded-default bg-white p-4 text-popover-foreground shadow-xl outline-hidden data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
23
|
+
className
|
|
24
|
+
)}
|
|
25
|
+
{...props}
|
|
26
|
+
/>
|
|
27
|
+
</PopoverPrimitive.Portal>
|
|
28
|
+
));
|
|
29
|
+
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
|
30
|
+
|
|
31
|
+
export { Popover, PopoverTrigger, PopoverContent };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { InputHTMLAttributes, forwardRef } from 'react';
|
|
4
|
+
|
|
5
|
+
type RadioSize = 'small' | 'normal' | 'large';
|
|
6
|
+
|
|
7
|
+
interface IRadioProps
|
|
8
|
+
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'> {
|
|
9
|
+
label: string;
|
|
10
|
+
size?: RadioSize;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const Radio = forwardRef(
|
|
14
|
+
(
|
|
15
|
+
{ id, label, onChange, size = 'normal', ...props }: IRadioProps,
|
|
16
|
+
ref: any
|
|
17
|
+
) => {
|
|
18
|
+
const sizeClasses = {
|
|
19
|
+
small: 'w-3 h-3 text-xs',
|
|
20
|
+
normal: 'w-4 h-4 text-base',
|
|
21
|
+
large: 'w-6 h-6 text-lg'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const inputSizeClass = sizeClasses[size];
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className={`flex items-center gap-4 ${sizeClasses[size]}`}>
|
|
28
|
+
<input
|
|
29
|
+
{...props}
|
|
30
|
+
id={id}
|
|
31
|
+
ref={ref}
|
|
32
|
+
type='radio'
|
|
33
|
+
className={`${inputSizeClass} border-green-500`}
|
|
34
|
+
/>
|
|
35
|
+
<label htmlFor={id} className='cursor-pointer'>
|
|
36
|
+
{label}
|
|
37
|
+
</label>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
Radio.displayName = 'Radio';
|
|
43
|
+
|
|
44
|
+
export default Radio;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { memo, useState } from 'react';
|
|
4
|
+
import ReactSlider from 'react-slider';
|
|
5
|
+
|
|
6
|
+
interface IRange {
|
|
7
|
+
initialValues?: number[];
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
onChange?: (value: number[]) => void;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Range = ({
|
|
15
|
+
min,
|
|
16
|
+
max,
|
|
17
|
+
onChange,
|
|
18
|
+
disabled = false,
|
|
19
|
+
initialValues
|
|
20
|
+
}: IRange) => {
|
|
21
|
+
const [rangeValue, setRangeValue] = useState<number[]>(
|
|
22
|
+
initialValues ?? [min || 0, max || 1000]
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className='w-full flex flex-col gap-[5px]'>
|
|
27
|
+
<p className='text-primary-900 text-sm select-none'>
|
|
28
|
+
{`${rangeValue[0]} - ${rangeValue[1]}`}
|
|
29
|
+
</p>
|
|
30
|
+
<ReactSlider
|
|
31
|
+
className='slider'
|
|
32
|
+
disabled={disabled}
|
|
33
|
+
min={min || 1}
|
|
34
|
+
max={max || 1000}
|
|
35
|
+
value={initialValues}
|
|
36
|
+
onChange={value => setRangeValue(value)}
|
|
37
|
+
ariaLabel={['Lower thumb', 'Upper thumb']}
|
|
38
|
+
onAfterChange={value => {
|
|
39
|
+
onChange?.(value);
|
|
40
|
+
}}
|
|
41
|
+
minDistance={10}
|
|
42
|
+
pearling
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const propsAreEqual = (prevProps: IRange, nextProps: IRange) =>
|
|
49
|
+
prevProps.min === nextProps.min &&
|
|
50
|
+
prevProps.max === nextProps.max &&
|
|
51
|
+
prevProps.disabled === nextProps.disabled &&
|
|
52
|
+
prevProps.initialValues === nextProps.initialValues;
|
|
53
|
+
|
|
54
|
+
export default memo(Range, propsAreEqual);
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
5
|
+
import { Check, CaretDown, CaretUp } from '@phosphor-icons/react';
|
|
6
|
+
|
|
7
|
+
import { cn } from '../utils/classes';
|
|
8
|
+
|
|
9
|
+
const Select = SelectPrimitive.Root;
|
|
10
|
+
const SelectGroup = SelectPrimitive.Group;
|
|
11
|
+
const SelectValue = SelectPrimitive.Value;
|
|
12
|
+
|
|
13
|
+
const SelectTrigger = React.forwardRef<
|
|
14
|
+
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
|
15
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
|
|
16
|
+
>(({ className, children, ...props }, ref) => (
|
|
17
|
+
<SelectPrimitive.Trigger
|
|
18
|
+
ref={ref}
|
|
19
|
+
className={cn(
|
|
20
|
+
'flex h-[50px] w-full items-center justify-between rounded-button bg-gray-100 px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
|
|
21
|
+
className
|
|
22
|
+
)}
|
|
23
|
+
{...props}
|
|
24
|
+
>
|
|
25
|
+
{children}
|
|
26
|
+
<SelectPrimitive.Icon asChild>
|
|
27
|
+
<CaretDown className='h-4 w-4 opacity-50' />
|
|
28
|
+
</SelectPrimitive.Icon>
|
|
29
|
+
</SelectPrimitive.Trigger>
|
|
30
|
+
));
|
|
31
|
+
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
|
32
|
+
|
|
33
|
+
const SelectScrollUpButton = React.forwardRef<
|
|
34
|
+
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
|
|
35
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
|
|
36
|
+
>(({ className, ...props }, ref) => (
|
|
37
|
+
<SelectPrimitive.ScrollUpButton
|
|
38
|
+
ref={ref}
|
|
39
|
+
className={cn(
|
|
40
|
+
'flex cursor-default items-center justify-center py-1',
|
|
41
|
+
className
|
|
42
|
+
)}
|
|
43
|
+
{...props}
|
|
44
|
+
>
|
|
45
|
+
<CaretUp className='h-4 w-4' />
|
|
46
|
+
</SelectPrimitive.ScrollUpButton>
|
|
47
|
+
));
|
|
48
|
+
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
|
|
49
|
+
|
|
50
|
+
const SelectScrollDownButton = React.forwardRef<
|
|
51
|
+
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
|
|
52
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
|
|
53
|
+
>(({ className, ...props }, ref) => (
|
|
54
|
+
<SelectPrimitive.ScrollDownButton
|
|
55
|
+
ref={ref}
|
|
56
|
+
className={cn(
|
|
57
|
+
'flex cursor-default items-center justify-center py-1',
|
|
58
|
+
className
|
|
59
|
+
)}
|
|
60
|
+
{...props}
|
|
61
|
+
>
|
|
62
|
+
<CaretDown className='h-4 w-4' />
|
|
63
|
+
</SelectPrimitive.ScrollDownButton>
|
|
64
|
+
));
|
|
65
|
+
SelectScrollDownButton.displayName =
|
|
66
|
+
SelectPrimitive.ScrollDownButton.displayName;
|
|
67
|
+
|
|
68
|
+
const SelectContent = React.forwardRef<
|
|
69
|
+
React.ElementRef<typeof SelectPrimitive.Content>,
|
|
70
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
|
71
|
+
>(({ className, children, position = 'popper', ...props }, ref) => (
|
|
72
|
+
<SelectPrimitive.Portal>
|
|
73
|
+
<SelectPrimitive.Content
|
|
74
|
+
ref={ref}
|
|
75
|
+
className={cn(
|
|
76
|
+
'relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-button bg-white text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
77
|
+
position === 'popper'
|
|
78
|
+
? 'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1'
|
|
79
|
+
: '',
|
|
80
|
+
className
|
|
81
|
+
)}
|
|
82
|
+
position={position}
|
|
83
|
+
{...props}
|
|
84
|
+
>
|
|
85
|
+
<SelectScrollUpButton />
|
|
86
|
+
<SelectPrimitive.Viewport
|
|
87
|
+
className={cn(
|
|
88
|
+
'p-1',
|
|
89
|
+
position === 'popper'
|
|
90
|
+
? 'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'
|
|
91
|
+
: ''
|
|
92
|
+
)}
|
|
93
|
+
>
|
|
94
|
+
{children}
|
|
95
|
+
</SelectPrimitive.Viewport>
|
|
96
|
+
<SelectScrollDownButton />
|
|
97
|
+
</SelectPrimitive.Content>
|
|
98
|
+
</SelectPrimitive.Portal>
|
|
99
|
+
));
|
|
100
|
+
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
|
101
|
+
|
|
102
|
+
const SelectLabel = React.forwardRef<
|
|
103
|
+
React.ElementRef<typeof SelectPrimitive.Label>,
|
|
104
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
|
|
105
|
+
>(({ className, ...props }, ref) => (
|
|
106
|
+
<SelectPrimitive.Label
|
|
107
|
+
ref={ref}
|
|
108
|
+
className={cn('py-1.5 pl-8 pr-2 text-sm font-semibold', className)}
|
|
109
|
+
{...props}
|
|
110
|
+
/>
|
|
111
|
+
));
|
|
112
|
+
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
|
113
|
+
|
|
114
|
+
const SelectItem = React.forwardRef<
|
|
115
|
+
React.ElementRef<typeof SelectPrimitive.Item>,
|
|
116
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
|
|
117
|
+
>(({ className, children, ...props }, ref) => (
|
|
118
|
+
<SelectPrimitive.Item
|
|
119
|
+
ref={ref}
|
|
120
|
+
className={cn(
|
|
121
|
+
'relative flex w-full cursor-default select-none items-center rounded-xs py-1.5 pl-8 pr-2 text-sm outline-hidden focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50',
|
|
122
|
+
className
|
|
123
|
+
)}
|
|
124
|
+
{...props}
|
|
125
|
+
>
|
|
126
|
+
<span className='absolute left-2 flex h-3.5 w-3.5 items-center justify-center'>
|
|
127
|
+
<SelectPrimitive.ItemIndicator>
|
|
128
|
+
<Check className='h-4 w-4' />
|
|
129
|
+
</SelectPrimitive.ItemIndicator>
|
|
130
|
+
</span>
|
|
131
|
+
|
|
132
|
+
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
|
133
|
+
</SelectPrimitive.Item>
|
|
134
|
+
));
|
|
135
|
+
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
|
136
|
+
|
|
137
|
+
const SelectSeparator = React.forwardRef<
|
|
138
|
+
React.ElementRef<typeof SelectPrimitive.Separator>,
|
|
139
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
|
|
140
|
+
>(({ className, ...props }, ref) => (
|
|
141
|
+
<SelectPrimitive.Separator
|
|
142
|
+
ref={ref}
|
|
143
|
+
className={cn('-mx-1 my-1 h-px bg-muted', className)}
|
|
144
|
+
{...props}
|
|
145
|
+
/>
|
|
146
|
+
));
|
|
147
|
+
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
|
|
148
|
+
|
|
149
|
+
export {
|
|
150
|
+
Select,
|
|
151
|
+
SelectGroup,
|
|
152
|
+
SelectValue,
|
|
153
|
+
SelectTrigger,
|
|
154
|
+
SelectContent,
|
|
155
|
+
SelectLabel,
|
|
156
|
+
SelectItem,
|
|
157
|
+
SelectSeparator,
|
|
158
|
+
SelectScrollUpButton,
|
|
159
|
+
SelectScrollDownButton
|
|
160
|
+
};
|