@chakra-ui/react#IconButton TypeScript Examples
The following examples show how to use
@chakra-ui/react#IconButton.
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: MenuButtons.tsx From calories-in with MIT License | 6 votes |
function MenuButtons({ onImport, onExport }: Props) {
return (
<Menu
arrow
align="end"
viewScroll="close"
menuButton={
<IconButton
aria-label="Foods actions"
icon={<MoreHorizontalStyled size={20} pointerEvents="none" />}
variant="outline"
/>
}
>
<MenuItem onClick={onImport}>
<DownloadStyled pointerEvents="none" mr={3} />
Import custom foods
</MenuItem>
<MenuItem onClick={onExport}>
<ShareStyled pointerEvents="none" mr={3} />
Export custom foods
</MenuItem>
</Menu>
)
}
Example #2
Source File: IconButtonPreview.tsx From openchakra with MIT License | 6 votes |
IconButtonPreview = ({ component }: Props) => {
const { isOver } = useDropComponent(component.id)
const {
props: { icon, ...props },
ref,
} = useInteractive(component, true)
if (isOver) {
props.bg = 'teal.50'
}
if (icon) {
if (Object.keys(icons).includes(icon)) {
const Icon = icons[icon as keyof typeof icons]
return <IconButton ref={ref} icon={<Icon path="" />} {...props} />
}
return null
}
return null
}
Example #3
Source File: UserListItem.tsx From next-crud with MIT License | 6 votes |
UserListItem = ({ id, username, onEdit, onDelete }: IProps) => {
return (
<Flex
direction="row"
align="center"
justify="space-between"
py={2}
width="100%"
>
<HStack spacing={8} align="center">
<Text>#{id}</Text>
<Text>{username}</Text>
</HStack>
<ButtonGroup spacing={2}>
<IconButton
aria-label="Edit"
icon={<EditIcon color="white" />}
colorScheme="blue"
onClick={() => onEdit(id)}
size="sm"
/>
<IconButton
aria-label="Delete"
icon={<DeleteIcon color="white" />}
colorScheme="red"
onClick={() => onDelete(id)}
size="sm"
/>
</ButtonGroup>
</Flex>
)
}
Example #4
Source File: ActionButton.tsx From openchakra with MIT License | 6 votes |
ActionButton = ({
icon,
as,
label,
onClick,
colorScheme,
isLoading,
...props
}: Props) => {
return (
<Tooltip hasArrow aria-label={label} label={label} zIndex={11} {...props}>
<IconButton
variant="ghost"
as={as}
isLoading={isLoading}
onClick={onClick}
icon={icon}
aria-label={label}
colorScheme={colorScheme}
size="xs"
/>
</Tooltip>
)
}
Example #5
Source File: DarkModeSwitch.tsx From ksana.in with Apache License 2.0 | 6 votes |
export function DarkModeSwitch() {
const { colorMode, toggleColorMode } = useColorMode()
const isDark: string | boolean = colorMode === 'dark'
return (
<IconButton
aria-label="Theme switcher"
onClick={toggleColorMode}
fontSize="20px"
borderRadius="md"
bgColor="orange.300"
_hover={{
bg: 'orange.500'
}}
icon={isDark ? <HiSun color="white" /> : <HiMoon color="white" />}
/>
)
}
Example #6
Source File: SortHandler.tsx From ke with MIT License | 6 votes |
function SortDirection({ value, onChange }: SortDirectionProps): JSX.Element {
switch (value) {
case 'asc':
return (
<IconButton
background={{}}
aria-label="По возрастанию"
icon={<ChevronsDown />}
onClick={() => onChange('desc')}
size="xs"
/>
)
case 'desc':
return (
<IconButton
background={{}}
aria-label="По убыванию"
icon={<ChevronsUp />}
onClick={() => onChange(null)}
size="xs"
/>
)
case null:
return (
<IconButton
background={{}}
aria-label="Сортировать"
icon={<Minus />}
onClick={() => onChange('asc')}
size="xs"
/>
)
default:
throw new TypeError(`Unknown sort direction: ${value}. Awaiting for 'asc' | 'desc' | null`)
}
}
Example #7
Source File: FusePoolCreatePage.tsx From rari-dApp with GNU Affero General Public License v3.0 | 6 votes |
WhitelistInfo = ({
whitelist,
addToWhitelist,
removeFromWhitelist,
}: {
whitelist: string[];
addToWhitelist: (user: string) => any;
removeFromWhitelist: (user: string) => any;
}) => {
const [_whitelistInput, _setWhitelistInput] = useState("");
const { t } = useTranslation();
const { fuse } = useRari();
const toast = useToast();
return (
<>
<OptionRow my={0} mb={4}>
<Input
width="100%"
value={_whitelistInput}
onChange={(event) => _setWhitelistInput(event.target.value)}
placeholder="0x0000000000000000000000000000000000000000"
_placeholder={{ color: "#FFF" }}
/>
<IconButton
flexShrink={0}
aria-label="add"
icon={<AddIcon />}
width="35px"
ml={2}
bg="#282727"
color="#FFF"
borderWidth="1px"
backgroundColor="transparent"
onClick={() => {
if (
fuse.web3.utils.isAddress(_whitelistInput) &&
!whitelist.includes(_whitelistInput)
) {
addToWhitelist(_whitelistInput);
_setWhitelistInput("");
} else {
toast({
title: "Error!",
description:
"This is not a valid ethereum address (or you have already entered this address)",
status: "error",
duration: 2000,
isClosable: true,
position: "top-right",
});
}
}}
_hover={{}}
_active={{}}
/>
</OptionRow>
{whitelist.length > 0 ? (
<Text mb={4} ml={4} width="100%">
<b>{t("Already added:")} </b>
{whitelist.map((user, index, array) => (
<Text
key={user}
className="underline-on-hover"
as="button"
onClick={() => removeFromWhitelist(user)}
>
{user}
{array.length - 1 === index ? null : <>, </>}
</Text>
))}
</Text>
) : null}
</>
);
}
Example #8
Source File: ExportButton.tsx From calories-in with MIT License | 6 votes |
function ExportButton({ ...rest }: Props) {
const screenSize = useScreenSize()
const dietForm = useDietForm()
const canExport = canExportDietForm(dietForm)
const commonProps: ButtonProps = {
isDisabled: !canExport,
...rest,
}
if (screenSize >= ScreenSize.Medium) {
return (
<Button
leftIcon={<Share size={16} pointerEvents="none" />}
variant="solid"
colorScheme="teal"
size="md"
{...commonProps}
>
Export
</Button>
)
}
return (
<IconButton
isDisabled={!canExport}
aria-label="Export"
colorScheme="teal"
size="md"
icon={<Share size={20} pointerEvents="none" />}
{...commonProps}
/>
)
}
Example #9
Source File: carousel.tsx From portfolio with MIT License | 6 votes |
Btn = ({ icon, as, left, right, isRight, handleImageDir }: BtnProps) => {
return (
<Box
top={"calc(50% - 20px)"}
right={right}
left={left}
position={"absolute"}
borderRadius={"30px"}
width={"40px"}
height={"40px"}
display={"flex"}
justifyContent={"center"}
alignItems={"center"}
cursor={"pointer"}
fontWeight={"bold"}
fontSize={"18px"}
zIndex={"2"}
onClick={() => (isRight ? handleImageDir(1) : handleImageDir(-1))}
>
<IconButton
aria-label="icon button"
icon={icon}
cursor="pointer"
as={as}
size="md"
colorScheme="teal"
borderRadius="full"
rounded="full"
/>
</Box>
);
}
Example #10
Source File: AddVariantButton.tsx From calories-in with MIT License | 6 votes |
function AddVariantButton({ ...rest }: Props) {
const screenSize = useScreenSize()
if (screenSize >= ScreenSize.Medium) {
return (
<Button
borderRadius="full"
size="md"
bg="white"
leftIcon={<CalendarPlus size={16} />}
variant="outline"
mr={2}
flexShrink={0}
{...rest}
>
Add day
</Button>
)
}
return (
<IconButton
aria-label="Add day"
borderRadius="full"
size="md"
bg="white"
icon={<CalendarPlus size={20} />}
variant="outline"
mr={2}
flexShrink={0}
{...rest}
/>
)
}
Example #11
Source File: Footer.tsx From phonepare with MIT License | 6 votes |
Footer: FC = () => {
return <Box as='footer' role='contentinfo' mx='auto' maxW='7xl' py='12' px={{ base: '4', md: '8' }}>
<Stack>
<Stack direction='row' spacing='4' align='center' justify='space-between'>
<Box>
<Link to='/'>
<Heading>Phonepare</Heading>
</Link>
<Text>휴대폰을 비교하세요.</Text>
</Box>
<Box>
<ButtonGroup variant='ghost' color='gray.600'>
<IconButton as={Link} to='/' aria-label='Home' icon={<FaHome fontSize='20px' />} />
<IconButton as='a' href='https://github.com/wonderlandpark/phonepare' aria-label='Github' icon={<FaGithub fontSize='20px' />} />
</ButtonGroup>
</Box>
</Stack>
<Text fontSize='sm' alignSelf={{ base: 'center', sm: 'start' }}>
© {new Date().getFullYear()} Junseo Park. All rights reserved.
</Text>
</Stack>
</Box>
}
Example #12
Source File: Trigger.tsx From calories-in with MIT License | 6 votes |
function Trigger({ forwardedRef, onClick, ...rest }: Props) {
const screenSize = useScreenSize()
const isPhone = screenSize <= ScreenSize.Small
return (
<Tooltip label="All days">
<IconButton
borderRadius="full"
bg="white"
size="md"
aria-label="Add variant"
icon={<ChevronDown size={20} pointerEvents="none" />}
variant="outline"
mr={isPhone ? 0 : 2}
ml={isPhone ? 2 : 0}
flexShrink={0}
ref={forwardedRef}
onClick={onClick}
{...rest}
/>
</Tooltip>
)
}
Example #13
Source File: ColorModeSwitcher.tsx From notebook with MIT License | 6 votes |
ColorModeSwitcher: React.FC<ColorModeSwitcherProps> = (props) => {
const { toggleColorMode } = useColorMode()
const text = useColorModeValue("dark", "light")
const SwitchIcon = useColorModeValue(FaMoon, FaSun)
return (
<IconButton
size="md"
fontSize="lg"
variant="ghost"
color="current"
marginLeft="2"
onClick={toggleColorMode}
icon={<SwitchIcon />}
aria-label={`Switch to ${text} mode`}
{...props}
/>
)
}
Example #14
Source File: RedoButton.tsx From calories-in with MIT License | 6 votes |
function RedoButton() {
const { redo } = useDietFormVersionsActions()
const { canRedo } = useDietFormVersions()
const screenSize = useScreenSize()
if (screenSize >= ScreenSize.Medium) {
return (
<Tooltip
label={
<TooltipCommandLabel
command="Redo last change"
kbdCombo={`${ctrlKeyName}+Shift+Z`}
/>
}
>
<Button
variant="solid"
leftIcon={<RotateCwStyled size={16} pointerEvents="none" />}
isDisabled={!canRedo}
onClick={() => redo()}
>
Redo
</Button>
</Tooltip>
)
}
return (
<IconButton
aria-label="Redo"
variant="solid"
icon={<RotateCwStyled size={20} pointerEvents="none" />}
isDisabled={!canRedo}
onClick={() => redo()}
/>
)
}
Example #15
Source File: page-footer.tsx From notebook with MIT License | 6 votes |
ExternalSocialLink = (props: ExternalSocialLinkProps) => {
const { href, label, icon, type, isExternal = true } = props;
return (
<IconButton
as={ChakraLink}
href={href}
target={isExternal ? "_blank" : "_self"}
aria-label={label}
icon={icon}
colorScheme={type}
{...iconProps}
/>
);
}
Example #16
Source File: Setup.tsx From bluebubbles-server with Apache License 2.0 | 5 votes |
NavBar = (): JSX.Element => {
const { colorMode, toggleColorMode } = useColorMode();
return (
<Flex
height="20"
alignItems="center"
borderBottomWidth="1px"
borderBottomColor={useColorModeValue('gray.200', 'gray.700')}
justifyContent='space-between'
p={4}
pl={6}
>
<Flex alignItems="center" justifyContent='flex-start'>
<img src={logo} className="logo" alt="logo" height={48} />
<Text fontSize="1xl" ml={2}>BlueBubbles</Text>
</Flex>
<Flex justifyContent='flex-end'>
<HStack spacing={{ base: '0', md: '1' }}>
<Tooltip label="Website Home" aria-label="website-tip">
<Link href="https://bluebubbles.app" style={{ textDecoration: 'none' }} target="_blank">
<IconButton size="lg" variant="ghost" aria-label="website" icon={<AiOutlineHome />} />
</Link>
</Tooltip>
<Tooltip label="BlueBubbles Web" aria-label="website-tip">
<Link href="https://bluebubbles.app/web" style={{ textDecoration: 'none' }} target="_blank">
<IconButton size="lg" variant="ghost" aria-label="bluebubbles web" icon={<FiMessageCircle />} />
</Link>
</Tooltip>
<Tooltip label="Support Us" aria-label="donate-tip">
<Link href="https://bluebubbles.app/donate" style={{ textDecoration: 'none' }} target="_blank">
<IconButton size="lg" variant="ghost" aria-label="donate" icon={<MdOutlineAttachMoney />} />
</Link>
</Tooltip>
<Tooltip label="Join our Discord" aria-label="discord-tip">
<Link href="https://discord.gg/yC4wr38" style={{ textDecoration: 'none' }} target="_blank">
<IconButton size="lg" variant="ghost" aria-label="discord" icon={<FaDiscord />} />
</Link>
</Tooltip>
<Tooltip label="Read our Source Code" aria-label="github-tip">
<Link href="https://github.com/BlueBubblesApp" style={{ textDecoration: 'none' }} target="_blank">
<IconButton size="lg" variant="ghost" aria-label="github" icon={<FiGithub />} />
</Link>
</Tooltip>
<Spacer />
<Divider orientation="vertical" width={1} height={15} borderColor='gray' />
<Spacer />
<Spacer />
<Spacer />
<FormControl display='flex' alignItems='center'>
<Box mr={2}><MdOutlineDarkMode size={20} /></Box>
<Switch id='theme-mode-toggle' onChange={toggleColorMode} isChecked={colorMode === 'light'} />
<Box ml={2}><MdOutlineLightMode size={20} /></Box>
</FormControl>
</HStack>
</Flex>
</Flex>
);
}
Example #17
Source File: SharePopover.tsx From ksana.in with Apache License 2.0 | 5 votes |
SharePopover = ({ url }: SharePopoverProps) => {
const [isLoadingShare, setLoadingShare] = useState<boolean>(false)
const [showShare, setShowShare] = useState<boolean>(false)
const [text, setText] = useState<string>('')
const parsedUrl = encodeURIComponent(url)
const handleShare = async (url: string) => {
setLoadingShare(true)
const d = await getMeta(url)
setText(encodeURIComponent(d.description))
setShowShare(true)
setLoadingShare(false)
}
return (
<Popover
isOpen={showShare}
onClose={() => {
setShowShare(false)
}}
isLazy
placement="bottom"
>
<PopoverTrigger>
<IconButton
onClick={() => {
handleShare(url)
}}
aria-label="Share url"
fontSize="20px"
variant="ghost"
borderRadius="md"
isLoading={isLoadingShare}
icon={<HiShare color="#ED8936" />}
/>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverCloseButton />
<PopoverHeader>Bagikan tautan anda</PopoverHeader>
<PopoverBody>
<Stack direction="row" justifyContent="center">
<Link isExternal href={`https://api.whatsapp.com/send?text=${text}+%0A+${parsedUrl}`}>
<IconButton
borderRadius="md"
colorScheme="green"
aria-label="Share whatsapp"
icon={<FaWhatsapp />}
/>
</Link>
<Link
isExternal
href={`https://twitter.com/intent/tweet?text=${text}+%0A+${parsedUrl}`}
>
<IconButton
borderRadius="md"
colorScheme="twitter"
aria-label="Share twitter"
icon={<FaTwitter />}
/>
</Link>
<Link
isExternal
href={`https://www.facebook.com/sharer/sharer.php?quote=${text}&u=${parsedUrl}`}
>
<IconButton
borderRadius="md"
colorScheme="facebook"
aria-label="Share Facebook"
icon={<FaFacebook />}
/>
</Link>
</Stack>
</PopoverBody>
</PopoverContent>
</Popover>
)
}
Example #18
Source File: LocalPortField.tsx From bluebubbles-server with Apache License 2.0 | 5 votes |
LocalPortField = ({ helpText }: LocalPortFieldProps): JSX.Element => {
const dispatch = useAppDispatch();
const port: number = useAppSelector(state => state.config.socket_port) ?? 1234;
const [newPort, setNewPort] = useState(port);
const [portError, setPortError] = useState('');
const hasPortError: boolean = (portError?? '').length > 0;
useEffect(() => { setNewPort(port); }, [port]);
/**
* A handler & validator for saving a new port.
*
* @param theNewPort - The new port to save
*/
const savePort = (theNewPort: number): void => {
// Validate the port
if (theNewPort < 1024 || theNewPort > 65635) {
setPortError('Port must be between 1,024 and 65,635');
return;
} else if (theNewPort === port) {
setPortError('You have not changed the port since your last save!');
return;
}
dispatch(setConfig({ name: 'socket_port', value: theNewPort }));
if (hasPortError) setPortError('');
showSuccessToast({
id: 'settings',
duration: 4000,
description: 'Successfully saved new port! Restarting Proxy & HTTP services...'
});
};
return (
<FormControl isInvalid={hasPortError}>
<FormLabel htmlFor='socket_port'>Local Port</FormLabel>
<Flex flexDirection='row' justifyContent='flex-start' alignItems='center'>
<Input
id='socket_port'
type='number'
maxWidth="5em"
value={newPort}
onChange={(e) => {
if (hasPortError) setPortError('');
setNewPort(Number.parseInt(e.target.value));
}}
/>
<IconButton
ml={3}
verticalAlign='top'
aria-label='Save port'
icon={<AiOutlineSave />}
onClick={() => savePort(newPort)}
/>
</Flex>
{!hasPortError ? (
<FormHelperText>
{helpText ?? 'Enter the local port for the socket server to run on'}
</FormHelperText>
) : (
<FormErrorMessage>{portError}</FormErrorMessage>
)}
</FormControl>
);
}
Example #19
Source File: ScrollButtons.tsx From calories-in with MIT License | 5 votes |
function ScrollButtons({
showsButtons,
scrollNodeRef,
canScrollLeft,
canScrollRight,
}: Props) {
function onTest() {
animateScrollLeft(scrollNodeRef, SCROLL_DELTA)
}
function onTest2() {
animateScrollLeft(scrollNodeRef, -SCROLL_DELTA)
}
return (
<Fade in={showsButtons} unmountOnExit={true}>
<IconButton
bg="white"
borderTopLeftRadius="full"
borderBottomLeftRadius="full"
size="md"
aria-label="Add variant"
icon={<ArrowLeft size={20} pointerEvents="none" />}
variant="outline"
onClick={onTest2}
ml={3}
flexShrink={0}
isDisabled={!canScrollLeft}
/>
<IconButton
bg="white"
borderTopRightRadius="full"
borderBottomRightRadius="full"
size="md"
aria-label="Add variant"
icon={<ArrowRight size={20} pointerEvents="none" />}
variant="outline"
onClick={onTest}
flexShrink={0}
isDisabled={!canScrollRight}
/>
</Fade>
)
}
Example #20
Source File: ColorModeSwitcher.tsx From portfolio with MIT License | 5 votes |
ColorModeSwitcher: React.FC<ColorModeSwitcherProps> = props => {
const { toggleColorMode } = useColorMode();
const text = useColorModeValue("dark", "light");
const SwitchIcon = useColorModeValue(FaMoon, FaSun);
const [play] = useSound(lightswitch, {
volume: 0.05,
sprite: {
on: [0, 300],
off: [500, 300]
}
});
const handleClick = () => {
text === "dark" ? play({ id: "on" }) : play({ id: "off" });
toggleColorMode();
};
return (
<Tooltip
label={text === "dark" ? "Dark mode" : "Light mode"}
aria-label="A tooltip"
>
<IconButton
size="md"
fontSize="md"
variant="ghost"
color="current"
marginLeft="2"
onClick={handleClick}
icon={<SwitchIcon />}
aria-label={`Switch to ${text} mode`}
_hover={{
bg: useColorModeValue("gray.200", "gray.900")
}}
{...props}
/>
</Tooltip>
);
}
Example #21
Source File: CloseButton.tsx From fresh-coupons with GNU General Public License v3.0 | 5 votes |
CloseButton = (props: IconButtonProps) => (
<IconButton fontSize="1.5em" variant="ghost" icon={<HiX />} {...props} />
)
Example #22
Source File: Wrapper.tsx From ksana.in with Apache License 2.0 | 5 votes |
export function DashboardWrapper({ user }: IDashboardWrapperProps) {
const [showAdd, setShowAdd] = useState<boolean>(false)
const handleShowAdd = () => {
setShowAdd(!showAdd)
}
const handleSuccessAdd = () => {
setShowAdd(false)
window.location.reload()
}
return (
<Box width={{ base: '100%' }}>
{user && user.id ? (
<Stack spacing={8} width="100%">
<Flex justifyContent="space-between" alignItems="center">
<Heading as="h3" size="2xl" color="orange.400" display="flex">
<Text>Tautan Saya</Text>
</Heading>
<IconButton
onClick={handleShowAdd}
aria-label="Tambah baru"
fontSize="20px"
borderRadius="md"
bg={'orange.400'}
_hover={{
bg: 'orange.500'
}}
_focus={{
bg: 'orange.500'
}}
icon={showAdd ? <HiMinus color="white" /> : <HiPlus color="white" />}
/>
</Flex>
{showAdd ? <UrlForm user={user} onSuccess={handleSuccessAdd} /> : null}
<UrlList user={user} isFormVisible={showAdd} onShowForm={handleShowAdd} />
</Stack>
) : null}
</Box>
)
}
Example #23
Source File: PollIntervalField.tsx From bluebubbles-server with Apache License 2.0 | 5 votes |
PollIntervalField = ({ helpText }: PollIntervalFieldProps): JSX.Element => {
const dispatch = useAppDispatch();
const pollInterval: number = useAppSelector(state => state.config.db_poll_interval) ?? 1000;
const [newInterval, setNewInterval] = useState(pollInterval);
const [intervalError, setIntervalError] = useState('');
const hasIntervalError: boolean = (intervalError?? '').length > 0;
useEffect(() => { setNewInterval(pollInterval); }, [pollInterval]);
/**
* A handler & validator for saving a new poll interval
*
* @param theNewInterval - The new interval to save
*/
const saveInterval = (theNewInterval: number): void => {
// Validate the interval
if (theNewInterval < 500) {
setIntervalError('The interval must be at least 500ms or else database locks can occur');
return;
}
dispatch(setConfig({ name: 'db_poll_interval', value: theNewInterval }));
if (hasIntervalError) setIntervalError('');
showSuccessToast({
id: 'settings',
duration: 4000,
description: 'Successfully saved new poll interval! Restarting DB listeners...'
});
};
return (
<FormControl isInvalid={hasIntervalError}>
<FormLabel htmlFor='db_poll_interval'>Database Poll Interval (ms)</FormLabel>
<Flex flexDirection='row' justifyContent='flex-start' alignItems='center'>
<Input
id='db_poll_interval'
type='number'
maxWidth="5em"
value={newInterval}
onChange={(e) => {
if (hasIntervalError) setIntervalError('');
setNewInterval(Number.parseInt(e.target.value));
}}
/>
<IconButton
ml={3}
verticalAlign='top'
aria-label='Save poll interval'
icon={<AiOutlineSave />}
onClick={() => saveInterval(newInterval)}
/>
</Flex>
{!hasIntervalError ? (
<FormHelperText>
{helpText ?? 'Enter how often (in milliseconds) you want the server to check for new messages in the database'}
</FormHelperText>
) : (
<FormErrorMessage>{intervalError}</FormErrorMessage>
)}
</FormControl>
);
}
Example #24
Source File: index.tsx From jsonschema-editor-react with Apache License 2.0 | 5 votes |
DropPlus: React.FunctionComponent<DropPlusProps> = (
props: React.PropsWithChildren<DropPlusProps>
) => {
const itemState = useState(props.itemStateProp);
const parentState = useState(props.parentStateProp);
const parentStateOrNull: State<JSONSchema7> | undefined = parentState.ornull;
const propertiesOrNull:
| State<{
[key: string]: JSONSchema7Definition;
}>
| undefined = parentStateOrNull.properties.ornull;
const itemPropertiesOrNull:
| State<{
[key: string]: JSONSchema7Definition;
}>
| undefined = itemState.properties.ornull;
if (props.isDisabled) {
return <div />;
}
if (!parentStateOrNull) {
return <></>;
}
return (
<Popover trigger="hover">
<PopoverTrigger>
<IconButton
isRound
size="sm"
mt={2}
mb={2}
mr={2}
variant="link"
colorScheme="green"
fontSize="16px"
icon={<IoIosAddCircleOutline />}
aria-label="Add Child Node"
/>
</PopoverTrigger>
<PopoverContent border="0" zIndex={4} width="100px" color="white">
<Stack>
<Button
colorScheme="blue"
variant="outline"
size="xs"
onClick={() => {
const fieldName = `field_${random()}`;
propertiesOrNull
?.nested(fieldName)
.set(getDefaultSchema(DataType.string) as JSONSchema7);
}}
>
Sibling Node
</Button>
<Button
size="xs"
colorScheme="orange"
variant="outline"
onClick={() => {
if (itemState.properties) {
const fieldName = `field_${random()}`;
itemPropertiesOrNull
?.nested(fieldName)
.set(getDefaultSchema(DataType.string) as JSONSchema7);
}
}}
>
Child Node
</Button>
</Stack>
</PopoverContent>
</Popover>
);
}
Example #25
Source File: footer.tsx From portfolio with MIT License | 5 votes |
Footer = () => {
return (
<Stack
as="footer"
isInline
spacing={[1, 2]}
p={4}
justifyContent="space-between"
alignItems="center"
w={["100%", "85%", "80%"]}
maxW={800}
mx="auto"
>
<Flex
flexDirection={["column", "column", "row"]}
flexFlow={["column-reverse", "column-reverse"]}
justifyContent={["center", "space-between"]}
alignItems="center"
w="100%"
ju
>
{/* <HStack> */}
<Text
textAlign="center"
fontSize="sm"
color={useColorModeValue("gray.500", "gray.200")}
>
© {new Date().getFullYear()} Muhammad Ahmad{" "}
</Text>
{/* <Box fontSize="md" textAlign="left">
Website built with
<Box
as="span"
mx="2"
_before={{
cursor: "default",
content: '"❤️"'
}}
_hover={{
_before: {
content: '"☕️"'
}
}}
/>
in Pakistan{" "}??
</Box> */}
{/* </HStack> */}
<Box textAlign="center">
{siteConfig.author.accounts.map((sc, index) => (
<IconButton
key={index}
as={Link}
isExternal
href={sc.url}
aria-label={sc.label}
size="lg"
colorScheme={sc.type}
icon={sc.icon}
{...iconProps}
/>
))}
</Box>
</Flex>
</Stack>
);
}
Example #26
Source File: Sidebar.tsx From openchakra with MIT License | 4 votes |
Menu = () => {
const [searchTerm, setSearchTerm] = useState('')
return (
<DarkMode>
<Box
maxH="calc(100vh - 3rem)"
overflowY="auto"
overflowX="visible"
boxShadow="xl"
flex="0 0 14rem"
p={5}
m={0}
as="menu"
backgroundColor="#2e3748"
width="15rem"
>
<InputGroup size="sm" mb={4}>
<Input
value={searchTerm}
color="gray.300"
placeholder="Search component…"
onChange={(event: ChangeEvent<HTMLInputElement>) =>
setSearchTerm(event.target.value)
}
borderColor="rgba(255, 255, 255, 0.04)"
bg="rgba(255, 255, 255, 0.06)"
_hover={{
borderColor: 'rgba(255, 255, 255, 0.08)',
}}
zIndex={0}
/>
<InputRightElement zIndex={1}>
{searchTerm ? (
<IconButton
color="gray.300"
aria-label="clear"
icon={<CloseIcon path="" />}
size="xs"
onClick={() => setSearchTerm('')}
/>
) : (
<SearchIcon path="" color="gray.300" />
)}
</InputRightElement>
</InputGroup>
{(Object.keys(menuItems) as ComponentType[])
.filter(c => c.toLowerCase().includes(searchTerm.toLowerCase()))
.map(name => {
const { children, soon } = menuItems[name] as MenuItem
if (children) {
const elements = Object.keys(children).map(childName => (
<DragItem
isChild
key={childName}
label={childName}
type={childName as any}
id={childName as any}
rootParentType={menuItems[name]?.rootParentType || name}
>
{childName}
</DragItem>
))
return [
<DragItem
isMeta
soon={soon}
key={`${name}Meta`}
label={name}
type={`${name}Meta` as any}
id={`${name}Meta` as any}
rootParentType={menuItems[name]?.rootParentType || name}
>
{name}
</DragItem>,
...elements,
]
}
return (
<DragItem
soon={soon}
key={name}
label={name}
type={name as any}
id={name as any}
rootParentType={menuItems[name]?.rootParentType || name}
>
{name}
</DragItem>
)
})}
</Box>
</DarkMode>
)
}
Example #27
Source File: index.tsx From calories-in with MIT License | 4 votes |
function FoodItem({
food,
isSelected = false,
onPreview,
onChoose,
usageType = 'selectOrPreview',
...rest
}: Props) {
function onInfoButtonClick(event: MouseEvent<HTMLButtonElement>) {
event.stopPropagation()
onPreview(food)
}
const oneTimeCheckActions = useOneTimeCheckActions()
const shouldAnimateAppear = oneTimeCheckActions.checkAndReset(
`food-appear-${food.id}`
)
const shouldAnimateFlash = oneTimeCheckActions.checkAndReset(
`food-flash-${food.id}`
)
return (
<Box
pb={2}
onClick={() => {
if (usageType === 'previewOnly') {
onPreview(food)
} else if (usageType === 'selectOrPreview') {
onChoose(food)
}
}}
{...rest}
>
<AnimateAppear shouldAnimate={shouldAnimateAppear}>
<Flex
cursor={usageType !== 'nonInteractive' ? 'pointer' : undefined}
_hover={
usageType !== 'nonInteractive'
? {
backgroundColor: !isSelected ? 'gray.50' : undefined,
}
: undefined
}
position="relative"
transition="border 150ms ease-out"
borderColor={isSelected ? 'teal.500' : 'gray.200'}
backgroundColor={isSelected ? 'gray.50' : 'white'}
borderWidth="1px"
borderRadius={6}
overflow="hidden"
justifyContent="space-between"
alignItems="center"
p={3}
height="64px"
>
{shouldAnimateFlash && (
<DisappearingBox shouldAnimate={shouldAnimateFlash} />
)}
<FoodInfo
nameNoOfLines={1}
food={food}
energy={food.energy}
position="relative"
zIndex={1}
/>
{usageType === 'selectOrPreview' && (
<Tooltip label="Food details">
<IconButton
aria-label="Food details"
icon={<InfoStyled size={20} pointerEvents="none" />}
variant="ghost"
onClick={onInfoButtonClick}
position="relative"
zIndex={1}
/>
</Tooltip>
)}
</Flex>
</AnimateAppear>
</Box>
)
}
Example #28
Source File: TopNavigation.tsx From website with MIT License | 4 votes |
TopNavigation: React.FC<TopNavigationProps> = ({ title }) => {
const { isOpen, onOpen, onClose } = useDisclosure()
return (
<Grid
as="nav"
templateColumns={`1fr 1fr minmax(auto, ${theme.sizes['6xl']}) 1fr 1fr`}
backgroundColor="gray.900"
color="white"
height={['88px', '80px']}
zIndex={50}
>
<List display="flex" flexWrap="wrap" alignItems="center" gridColumn="3/4" m={0} p={0}>
<ListItem display="flex" alignItems="center" pos="relative" h="100%" mr="auto">
<NextChakraLink
href="/"
display="flex"
alignItems="center"
py=".5rem"
px="1rem"
h="100%"
_hover={{ bg: 'rgba(255, 255, 255, 0.1)', textDecoration: 'none' }}
>
<Logo height={40} fill={theme.colors.white} title={title} />
</NextChakraLink>
</ListItem>
<ListItem display={['none', 'flex']} alignItems="center" h="100%">
<NextChakraLink
href="/community"
display="flex"
alignItems="center"
py="1.5rem"
px="1rem"
color="inherit"
h="100%"
lineHeight={1}
_hover={{ bg: 'rgba(255, 255, 255, 0.1)', textDecoration: 'none' }}
>
Komunitas
</NextChakraLink>
</ListItem>
<ListItem display={['none', 'flex']} alignItems="center" h="100%">
<NextChakraLink
href="/submit-a-talk"
display="flex"
alignItems="center"
py="1.5rem"
px="1rem"
color="inherit"
h="100%"
lineHeight={1}
_hover={{ bg: 'rgba(255, 255, 255, 0.1)', textDecoration: 'none' }}
>
Ajukan Topik
</NextChakraLink>
</ListItem>
<ListItem display={['none', 'flex']} alignItems="center" h="100%">
<NextChakraLink
href="/faq"
display="flex"
alignItems="center"
py="1.5rem"
px="1rem"
color="inherit"
h="100%"
lineHeight={1}
_hover={{ bg: 'rgba(255, 255, 255, 0.1)', textDecoration: 'none' }}
>
FAQ
</NextChakraLink>
</ListItem>
<ListItem py="1.5rem" px="1rem" display={['flex', 'none']} alignItems="center" h="100%">
<IconButton variant="outline" aria-label="Open menu" icon={<HamburgerIcon />} onClick={onOpen} />
<Drawer isOpen={isOpen} placement="right" onClose={onClose}>
<DrawerOverlay />
<DrawerContent>
<DrawerCloseButton />
<DrawerHeader>Menu Utama</DrawerHeader>
<DrawerBody>
<NextChakraLink
href="/community"
display="flex"
alignItems="center"
py="1.5rem"
px="1rem"
color="inherit"
lineHeight={1}
_hover={{ bg: 'rgba(255, 255, 255, 0.1)', textDecoration: 'none' }}
>
Komunitas
</NextChakraLink>
<NextChakraLink
href="/submit-a-talk"
display="flex"
alignItems="center"
py="1.5rem"
px="1rem"
color="inherit"
lineHeight={1}
_hover={{ bg: 'rgba(255, 255, 255, 0.1)', textDecoration: 'none' }}
>
Ajukan Topik
</NextChakraLink>
<NextChakraLink
href="/faq"
display="flex"
alignItems="center"
py="1.5rem"
px="1rem"
color="inherit"
lineHeight={1}
_hover={{ bg: 'rgba(255, 255, 255, 0.1)', textDecoration: 'none' }}
>
FAQ
</NextChakraLink>
</DrawerBody>
</DrawerContent>
</Drawer>
</ListItem>
</List>
</Grid>
)
}
Example #29
Source File: ChatForm.tsx From takeout-app with MIT License | 4 votes |
ChatForm: React.FC<Props> = ({ track, channel }) => {
const chat = useChat();
const { data: session } = Api.useSession();
const isStaff = session?.attendee?.is_staff;
const [errorAlert, setErrorAlert] = React.useState<JSX.Element | null>(null);
const [isRequesting, setIsRequesting] = React.useState<boolean>(false);
const { register, handleSubmit, reset, setFocus, watch } = useForm<{
message: string;
asAdmin: boolean;
}>({
defaultValues: {
message: "",
asAdmin: false,
},
});
const asAdmin = watch("asAdmin");
const onSubmit = handleSubmit(async (data) => {
if (!chat.session || !channel) return;
if (isRequesting) return;
setIsRequesting(true);
setErrorAlert(null);
try {
if (data.asAdmin && isStaff) {
await Api.sendChatMessage(track.slug, data.message, true);
} else {
// Workaround: aws-sdk-v3 sigv4 fails to generate correct signature for payload containing emoji...
if (/\p{Extended_Pictographic}/u.test(data.message)) {
await Api.sendChatMessage(track.slug, data.message, false);
} else {
await chat.session.postMessage(channel, data.message);
}
}
reset({ message: "", asAdmin: false });
} catch (e) {
setErrorAlert(
<Box my={2}>
<ErrorAlert error={e} />
</Box>,
);
}
setFocus("message");
setIsRequesting(false);
});
const shouldDisable = !session?.attendee || !chat.session || !channel;
// TODO: errorAlert to toast
return (
<Box p="16px" bgColor="#ffffff" borderTop="1px solid" borderColor={Colors.chatBorder}>
{errorAlert}
<form onSubmit={onSubmit}>
<VStack w="100%">
{session && !session.attendee?.is_ready ? (
<Box w="100%">
<Alert status="warning">
<AlertIcon />
<Text as="span">
Set your name at{" "}
<Link as={RouterLink} to="/attendee" textDecoration="underline">
Settings
</Link>{" "}
page
</Text>
</Alert>
</Box>
) : null}
<Box w="100%">
<Textarea
as={TextareaAutoSize}
{...register("message")}
size="sm"
placeholder={asAdmin ? "SAY SOMETHING AS ADMIN..." : "Send a message"}
isRequired
isDisabled={shouldDisable}
autoComplete="off"
rows={1}
minRows={1}
maxRows={4}
onKeyPress={(e) => {
if (e.key == "Enter") {
e.preventDefault();
onSubmit();
}
}}
css={{ resize: "none" }}
/>
</Box>
<Flex w="100%" alignItems="flex-end" direction="row-reverse" justifyContent="space-between">
<IconButton
icon={<SendIcon boxSize="14px" />}
minW="30px"
w="30px"
h="30px"
aria-label="Send"
type="submit"
isLoading={isRequesting}
isDisabled={shouldDisable}
/>
{isStaff ? (
<Tooltip label="Send as an official announcement" aria-label="">
<FormControl display="flex" alignSelf="center" h="30px">
<FormLabel htmlFor="ChatForm__asAdmin" aria-hidden="true" m={0} mr={1}>
<CampaignIcon w="24px" h="24px" />
</FormLabel>
<Switch
aria-label="Send as an official announcement"
id="ChatForm__asAdmin"
size="sm"
isChecked={asAdmin}
isDisabled={shouldDisable}
{...register("asAdmin")}
/>
</FormControl>
</Tooltip>
) : null}
</Flex>
</VStack>
</form>
</Box>
);
}