theme-ui#ThemeUICSSObject TypeScript Examples
The following examples show how to use
theme-ui#ThemeUICSSObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From slice-machine with Apache License 2.0 | 5 votes |
VarationsPopover: React.FunctionComponent<{
buttonSx?: ThemeUICSSObject;
defaultValue?: Models.VariationSM;
// eslint-disable-next-line @typescript-eslint/ban-types
onNewVariation?: Function;
variations: ReadonlyArray<Models.VariationSM>;
onChange: (selected: Models.VariationSM) => void;
}> = ({ buttonSx, defaultValue, variations, onNewVariation, onChange }) => {
const [isOpen, setIsOpen] = useState(false);
const [current, setCurrent] = useState<Models.VariationSM>(
defaultValue || variations[0]
);
useEffect(() => {
if (defaultValue) {
setCurrent(defaultValue);
}
}, [defaultValue]);
const TRANSITION_DURATION = 200; //ms
const handleChange = function (variation: Models.VariationSM) {
setIsOpen(false);
setCurrent(variation);
setTimeout(() => onChange(variation), TRANSITION_DURATION + 10); // time to properly close the popover with transition
};
const MenuItemAction = (
<Box sx={{ p: 2 }}>
<Button
variant="transparent"
sx={{ color: "text" }}
onClick={() => {
setIsOpen(false);
if (onNewVariation) {
onNewVariation();
}
}}
>
+ Add new variation
</Button>
</Box>
);
return (
<div>
<Popover
align="start"
isOpen={isOpen}
onClickOutside={() => setIsOpen(false)}
positions={["bottom"]}
padding={10}
content={() => (
<MenuList
defaultValue={current}
variations={variations}
onChange={handleChange}
MenuItemAction={onNewVariation ? MenuItemAction : undefined}
/>
)}
containerClassName={"variationSelectorContainer"}
>
<Button
sx={{
fontSize: 14,
p: 2,
pl: 3,
display: "flex",
alignItems: "center",
justifyContent: "space-between",
...buttonSx,
}}
variant="secondary"
onClick={() => setIsOpen(!isOpen)}
>
{current.name} <RiArrowDropDownLine size="24px" />
</Button>
</Popover>
</div>
);
}