review chip input
This commit is contained in:
parent
9047ab1668
commit
77ae395c88
@ -17,4 +17,10 @@
|
|||||||
background-color: var(--input-chip-hovered-background);
|
background-color: var(--input-chip-hovered-background);
|
||||||
border-color: var(--input-chip-hovered-border);
|
border-color: var(--input-chip-hovered-border);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.label{
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,22 +5,44 @@ import React from "react";
|
|||||||
import IconButton from "../../IconButton";
|
import IconButton from "../../IconButton";
|
||||||
import Typography, { ETypo, ETypoColor } from "../../Typography";
|
import Typography, { ETypo, ETypoColor } from "../../Typography";
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
|
import { IOption } from "../../Dropdown/DropdownMenu/DropdownOption";
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
text: string;
|
option: IOption;
|
||||||
className?: string;
|
className?: string;
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Chip(props: IProps) {
|
export default function Chip(props: IProps) {
|
||||||
const { className, text, onDelete } = props;
|
const { className, option, onDelete } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(classes["root"], className)}>
|
<div className={classNames(classes["root"], className)}>
|
||||||
<Typography typo={ETypo.TEXT_MD_SEMIBOLD} color={ETypoColor.INPUT_CHIP_CONTRAST}>
|
<Typography typo={ETypo.TEXT_MD_SEMIBOLD} color={ETypoColor.INPUT_CHIP_CONTRAST}>
|
||||||
{text}
|
{getLabelContent(option)}
|
||||||
</Typography>
|
</Typography>
|
||||||
<IconButton icon={<XMarkIcon />} onClick={onDelete} />
|
<IconButton icon={<XMarkIcon />} onClick={onDelete} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLabelContent(option: IOption) {
|
||||||
|
if (typeof option.label === "string") {
|
||||||
|
return (
|
||||||
|
<Typography typo={ETypo.TEXT_MD_SEMIBOLD} color={ETypoColor.INPUT_CHIP_CONTRAST}>
|
||||||
|
{option.label}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className={classes["label"]}>
|
||||||
|
<Typography typo={ETypo.TEXT_MD_LIGHT} color={ETypoColor.INPUT_CHIP_CONTRAST}>
|
||||||
|
{`${option.label.text} , `}
|
||||||
|
</Typography>
|
||||||
|
<Typography typo={ETypo.TEXT_MD_SEMIBOLD} color={ETypoColor.INPUT_CHIP_CONTRAST} type="span">
|
||||||
|
{option.label.subtext}
|
||||||
|
</Typography>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
.root {
|
.root {
|
||||||
border-radius: var(--input-radius, 0px);
|
border-radius: var(--input-radius, 0px);
|
||||||
border: 1px solid var(--input-main-border-filled, #6d7e8a);
|
border: 1px solid var(--input-main-border-default, #6d7e8a);
|
||||||
background: var(--input-background, #fff);
|
background: var(--input-background, #fff);
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
@ -10,21 +10,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
border-radius: var(--input-radius, 0px);
|
|
||||||
border: 1px solid var(--input-main-border-hovered, #b4bec5);
|
border: 1px solid var(--input-main-border-hovered, #b4bec5);
|
||||||
background: var(--input-background, #fff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&[data-has-value="true"] {
|
&[data-has-value="true"] {
|
||||||
border-radius: var(--input-radius, 0px);
|
|
||||||
border: 1px solid var(--input-main-border-filled, #6d7e8a);
|
border: 1px solid var(--input-main-border-filled, #6d7e8a);
|
||||||
background: var(--input-background, #fff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&[data-is-focused="true"] {
|
&[data-is-focused="true"] {
|
||||||
border-radius: var(--input-radius, 0px);
|
|
||||||
border: 1px solid var(--input-main-border-focused, #005bcb);
|
border: 1px solid var(--input-main-border-focused, #005bcb);
|
||||||
background: var(--input-background, #fff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&[data-is-disabled="true"] {
|
&[data-is-disabled="true"] {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import React, { useCallback, useEffect } from "react";
|
import React, { useCallback, useEffect } from "react";
|
||||||
|
|
||||||
import { getLabel } from "../../Dropdown";
|
|
||||||
import { IOption } from "../../Dropdown/DropdownMenu/DropdownOption";
|
import { IOption } from "../../Dropdown/DropdownMenu/DropdownOption";
|
||||||
import Chip from "../Chip";
|
import Chip from "../Chip";
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
@ -9,7 +8,7 @@ type IProps = {
|
|||||||
selectedOptions: IOption[];
|
selectedOptions: IOption[];
|
||||||
onSelectedOptionsChange: (options: IOption[]) => void;
|
onSelectedOptionsChange: (options: IOption[]) => void;
|
||||||
onChange?: (input: string) => void;
|
onChange?: (input: string) => void;
|
||||||
value?: string;
|
searchValue?: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
onClear?: () => void;
|
onClear?: () => void;
|
||||||
@ -21,7 +20,7 @@ export default function ChipContainer(props: IProps) {
|
|||||||
const {
|
const {
|
||||||
selectedOptions,
|
selectedOptions,
|
||||||
onChange,
|
onChange,
|
||||||
value: propValue,
|
searchValue,
|
||||||
placeholder = "Rechercher",
|
placeholder = "Rechercher",
|
||||||
disabled = false,
|
disabled = false,
|
||||||
onFocus,
|
onFocus,
|
||||||
@ -30,7 +29,7 @@ export default function ChipContainer(props: IProps) {
|
|||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [isFocused, setIsFocused] = React.useState(false);
|
const [isFocused, setIsFocused] = React.useState(false);
|
||||||
const [value, setValue] = React.useState(propValue || "");
|
const [value, setValue] = React.useState(searchValue || "");
|
||||||
|
|
||||||
const changeValue = useCallback(
|
const changeValue = useCallback(
|
||||||
(value: string) => {
|
(value: string) => {
|
||||||
@ -64,16 +63,20 @@ export default function ChipContainer(props: IProps) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (propValue !== undefined) {
|
if (searchValue !== undefined) {
|
||||||
setValue(propValue);
|
setValue(searchValue);
|
||||||
}
|
}
|
||||||
}, [propValue]);
|
}, [searchValue]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes["root"]} data-is-focused={isFocused} data-has-value={value !== ""} data-is-disabled={disabled}>
|
<div
|
||||||
|
className={classes["root"]}
|
||||||
|
data-is-focused={isFocused}
|
||||||
|
data-has-value={selectedOptions && selectedOptions.length > 0}
|
||||||
|
data-is-disabled={disabled}>
|
||||||
<div className={classes["content"]}>
|
<div className={classes["content"]}>
|
||||||
{selectedOptions.map((option) => (
|
{selectedOptions.map((option) => (
|
||||||
<Chip key={option.id} text={getLabel(option) ?? ""} onDelete={() => onChipDelete(option)} />
|
<Chip key={option.id} option={option} onDelete={() => onChipDelete(option)} />
|
||||||
))}
|
))}
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
@ -84,7 +84,7 @@ export default function AutocompleteMultiSelect(props: IProps) {
|
|||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={handleSearchChange}
|
onChange={handleSearchChange}
|
||||||
value={searchValue}
|
searchValue={searchValue}
|
||||||
onClear={() => handleChange(null)}
|
onClear={() => handleChange(null)}
|
||||||
onFocus={openable.open}
|
onFocus={openable.open}
|
||||||
selectedOptions={selectedOptions ?? []}
|
selectedOptions={selectedOptions ?? []}
|
||||||
@ -92,4 +92,4 @@ export default function AutocompleteMultiSelect(props: IProps) {
|
|||||||
/>
|
/>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -29,8 +29,8 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
padding: 0px var(--spacing-2, 16px);
|
padding: 0px var(--spacing-2, 16px);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex: 1 0 0;
|
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
|
flex: 1 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user