ui(components): migrates to new toolbar ui components and Numeric for Input InputRange and InputDoubleRange (#4728)
Co-authored-by: sedghi <ar.sedghi@gmail.com>
This commit is contained in:
1 parent
ac5ae4a29e
commit
a8d84443a9
116 files changed
+2930
-1038
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import React from 'react';
|
||||
import Numeric from '../Numeric';
|
||||
import { cn } from '../../lib/utils';
|
||||
|
||||
interface RowDoubleRangeProps {
|
||||
values: [number, number];
|
||||
onChange: (values: [number, number]) => void;
|
||||
minValue: number;
|
||||
maxValue: number;
|
||||
step: number;
|
||||
showLabel?: boolean;
|
||||
label?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const RowDoubleRange: React.FC<RowDoubleRangeProps> = ({
|
||||
values,
|
||||
onChange,
|
||||
minValue,
|
||||
maxValue,
|
||||
step,
|
||||
showLabel = false,
|
||||
label = '',
|
||||
className,
|
||||
}) => {
|
||||
return (
|
||||
<Numeric.Container
|
||||
mode="doubleRange"
|
||||
values={values}
|
||||
onChange={onChange}
|
||||
min={minValue}
|
||||
max={maxValue}
|
||||
step={step}
|
||||
className={cn('flex flex-col space-y-2', className)}
|
||||
>
|
||||
{showLabel && <Numeric.Label showValue>{label}</Numeric.Label>}
|
||||
<Numeric.DoubleRange showNumberInputs />
|
||||
</Numeric.Container>
|
||||
);
|
||||
};
|
||||
|
||||
export default RowDoubleRange;
|
||||
@@ -0,0 +1,65 @@
|
||||
import React from 'react';
|
||||
import Numeric from '../Numeric';
|
||||
import { cn } from '../../lib/utils';
|
||||
|
||||
interface RowInputRangeProps {
|
||||
value: number;
|
||||
onChange: (newValue: number) => void;
|
||||
minValue?: number;
|
||||
maxValue?: number;
|
||||
step?: number;
|
||||
label?: string;
|
||||
showLabel?: boolean;
|
||||
labelPosition?: 'left' | 'right';
|
||||
allowNumberEdit?: boolean;
|
||||
showNumberInput?: boolean;
|
||||
className?: string;
|
||||
containerClassName?: string;
|
||||
}
|
||||
|
||||
const RowInputRange: React.FC<RowInputRangeProps> = ({
|
||||
value,
|
||||
onChange,
|
||||
minValue = 0,
|
||||
maxValue = 100,
|
||||
step = 1,
|
||||
label = '',
|
||||
showLabel = false,
|
||||
labelPosition = 'right',
|
||||
allowNumberEdit = false,
|
||||
showNumberInput = true,
|
||||
className,
|
||||
containerClassName,
|
||||
}) => {
|
||||
const handleChange = (newValue: number | [number, number]) => {
|
||||
if (typeof newValue === 'number') {
|
||||
onChange(newValue);
|
||||
} else {
|
||||
onChange(newValue[0]);
|
||||
}
|
||||
};
|
||||
|
||||
const content = (
|
||||
<Numeric.Container
|
||||
mode="singleRange"
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
min={minValue}
|
||||
max={maxValue}
|
||||
step={step}
|
||||
className={cn('flex flex-row items-center space-x-2', className)}
|
||||
>
|
||||
{showLabel && label && labelPosition === 'left' && (
|
||||
<Numeric.Label showValue={showNumberInput}>{label}</Numeric.Label>
|
||||
)}
|
||||
<Numeric.SingleRange showNumberInput={allowNumberEdit && showNumberInput} />
|
||||
{showLabel && label && labelPosition === 'right' && (
|
||||
<Numeric.Label showValue={showNumberInput}>{label}</Numeric.Label>
|
||||
)}
|
||||
</Numeric.Container>
|
||||
);
|
||||
|
||||
return containerClassName ? <div className={containerClassName}>{content}</div> : content;
|
||||
};
|
||||
|
||||
export default RowInputRange;
|
||||
@@ -0,0 +1,58 @@
|
||||
import React from 'react';
|
||||
import { Label } from '../Label';
|
||||
import { Tabs, TabsList, TabsTrigger } from '../Tabs';
|
||||
import { cn } from '../../lib/utils';
|
||||
|
||||
interface RadioValue {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
interface RadioOption {
|
||||
id: string;
|
||||
name: string;
|
||||
value: string;
|
||||
values: RadioValue[];
|
||||
commands?: (val: string) => void;
|
||||
}
|
||||
|
||||
interface RowSegmentedControlProps {
|
||||
option: RadioOption;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const RowSegmentedControl: React.FC<RowSegmentedControlProps> = ({ option, className }) => {
|
||||
const handleValueChange = (newVal: string) => {
|
||||
if (option.commands) {
|
||||
option.commands(newVal);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn('flex items-center justify-between text-[13px]', className)}
|
||||
key={option.id}
|
||||
>
|
||||
<Label className="mr-2">{option.name}</Label>
|
||||
<div className="max-w-1/2">
|
||||
<Tabs
|
||||
value={option.value}
|
||||
onValueChange={handleValueChange}
|
||||
>
|
||||
<TabsList className="inline-flex space-x-1">
|
||||
{option.values.map(({ label, value: itemValue }, index) => (
|
||||
<TabsTrigger
|
||||
value={itemValue}
|
||||
key={`button-${option.id}-${index}`}
|
||||
>
|
||||
{label}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RowSegmentedControl;
|
||||
@@ -0,0 +1,99 @@
|
||||
import React from 'react';
|
||||
import RowInputRange from './RowInputRange';
|
||||
import RowSegmentedControl from './RowSegmentedControl';
|
||||
import RowDoubleRange from './RowDoubleRange';
|
||||
|
||||
const SETTING_TYPES = {
|
||||
RANGE: 'range',
|
||||
RADIO: 'radio',
|
||||
CUSTOM: 'custom',
|
||||
DOUBLE_RANGE: 'double-range',
|
||||
};
|
||||
|
||||
function ToolSettings({ options }) {
|
||||
if (!options) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof options === 'function') {
|
||||
return options();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="text-foreground space-y-2 pb-4">
|
||||
{options?.map(option => {
|
||||
if (option.condition && option.condition?.({ options }) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (option.type) {
|
||||
case SETTING_TYPES.RANGE:
|
||||
return renderRangeSetting(option);
|
||||
case SETTING_TYPES.RADIO:
|
||||
return renderRadioSetting(option);
|
||||
case SETTING_TYPES.DOUBLE_RANGE:
|
||||
return renderDoubleRangeSetting(option);
|
||||
case SETTING_TYPES.CUSTOM:
|
||||
return renderCustomSetting(option);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const renderRangeSetting = option => {
|
||||
return (
|
||||
<div
|
||||
className="flex items-center"
|
||||
key={option.id}
|
||||
>
|
||||
<div className="w-1/3 text-[13px]">{option.name}</div>
|
||||
<div className="w-2/3">
|
||||
<RowInputRange
|
||||
minValue={option.min}
|
||||
maxValue={option.max}
|
||||
step={option.step}
|
||||
value={option.value}
|
||||
onChange={value => option.commands?.(value)}
|
||||
allowNumberEdit={true}
|
||||
inputClassName="ml-1 w-4/5 cursor-pointer"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const renderRadioSetting = option => {
|
||||
return (
|
||||
<RowSegmentedControl
|
||||
key={option.id}
|
||||
option={option}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
function renderDoubleRangeSetting(option) {
|
||||
return (
|
||||
<RowDoubleRange
|
||||
key={option.id}
|
||||
values={option.value}
|
||||
onChange={option.commands}
|
||||
minValue={option.min}
|
||||
maxValue={option.max}
|
||||
step={option.step}
|
||||
showLabel={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const renderCustomSetting = option => {
|
||||
return (
|
||||
<div key={option.id}>
|
||||
{typeof option.children === 'function' ? option.children() : option.children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ToolSettings;
|
||||
@@ -0,0 +1 @@
|
||||
export { default as ToolSettings } from './ToolSettings';
|
||||
Reference in new issue
Block a user