@chakra-ui/react#useStyles TypeScript Examples

The following examples show how to use @chakra-ui/react#useStyles. 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: ReactSelectCustomization.tsx    From ke with MIT License 6 votes vote down vote up
function SingleValue<OptionType>({ ...props }: SingleValueProps<OptionType>): JSX.Element {
  const { singleValue } = useStyles()
  const { className, isDisabled } = props
  const theme = useTheme()
  return (
    <ClassNames>
      {({ cx: emotionCx, css }) => (
        <selectComponents.SingleValue
          {...props}
          className={emotionCx(className, {
            [css(chakraCss((singleValue as any)?._disabled)(theme))]: isDisabled,
          })}
        />
      )}
    </ClassNames>
  )
}
Example #2
Source File: ReactSelectCustomization.tsx    From ke with MIT License 6 votes vote down vote up
export function MultiValue<OptionType>(props: MultiValueProps<OptionType>): JSX.Element {
  const { children, className, cx, getStyles, innerProps, isDisabled, removeProps, data, selectProps } = props

  const { multiValueContainer, multiValueLabel, multiValueRemove } = useStyles()

  const externalClassName = (selectProps as ExtendedProps).componentsClasses?.MultiValue

  return (
    <ClassNames>
      {({ css, cx: emotionCx }) => (
        <Tag data={data} sx={multiValueContainer} {...innerProps} className={classNames(className, externalClassName)}>
          <TagLabel sx={multiValueLabel} className={className}>
            {children}
          </TagLabel>
          <TagCloseButton
            className={emotionCx(
              css(getStyles('multiValueRemove', props)),
              cx(
                {
                  'multi-value__remove': true,
                },
                className
              )
            )}
            isDisabled={isDisabled}
            {...removeProps}
            sx={multiValueRemove}
          />
        </Tag>
      )}
    </ClassNames>
  )
}
Example #3
Source File: ReactSelectCustomization.tsx    From ke with MIT License 6 votes vote down vote up
DropdownIndicator = <OptionType, IsMulti extends boolean = false>(
  props: IndicatorProps<OptionType, IsMulti>
): JSX.Element => {
  const { dropdownIndicator } = useStyles()
  return (
    <selectComponents.DropdownIndicator {...props}>
      <ChevronDownIcon sx={dropdownIndicator} />
    </selectComponents.DropdownIndicator>
  )
}
Example #4
Source File: WidgetWrapper.tsx    From ke with MIT License 5 votes vote down vote up
StyledWidgetWrapper = ({
  style,
  helpText,
  children,
  copyValue,
  useClipboard,
  notifier,
  name = '',
  description = '',
  required = false,
  containerProps,
  labelContainerProps,
  className,
}: WidgetWrapperProps): JSX.Element => {
  const error = containerErrorsStore.getState().find(({ widgetName }) => widgetName === name)
  const hasError = !!error
  const styles = useStyles()
  const widgetWrapperStyle = { ...(styles.widgetWrapper || {}), ...(style || {}) }
  return (
    <Box sx={widgetWrapperStyle} data-name={name} className={className}>
      {(helpText || useClipboard) && (
        <Flex {...(styles.labelWrapper as any)} {...labelContainerProps}>
          {helpText && (
            <Label isRequired={required} sx={styles.label}>
              {helpText}
            </Label>
          )}
          {useClipboard && <ToClipboard ml={1} value={copyValue} notifier={notifier} />}
        </Flex>
      )}
      <Box
        borderColor={hasError ? 'red.500' : undefined}
        borderWidth={hasError ? 1 : 0}
        borderRadius={3}
        sx={styles.controlWrapper}
        data-has-error={hasError}
        {...containerProps}
      >
        {children}
      </Box>
      {description && <Text sx={styles.description}>{description}</Text>}
      {!!error && (
        <Text mt={2} fontSize="sm" lineHeight="5" color="red.500">
          {error.errorText}
        </Text>
      )}
    </Box>
  )
}