How to use @chakra-ui/theme - 10 common examples

To help you get started, weโ€™ve selected a few @chakra-ui/theme examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chakra-ui / chakra-ui / packages / chakra-ui / src / Input / styles.ts View on Github external
const useInputStyle = (props: any) => {
  const theme = useTheme();
  const { colorMode } = useColorMode();

  const _props = { ...props, theme, colorMode };

  return {
    width: props.isFullWidth ? "100%" : undefined,
    ...baseProps,
    ...sizeProps(_props),
    ...variantProps(_props),
    // pb: "1px"
  };
};
github chakra-ui / chakra-ui / packages / chakra-ui / src / Avatar / Avatar.tsx View on Github external
showBorder,
    borderColor,
    ...props
  }: AvatarProps,
  ref: React.Ref,
) {
  const avatarStyleProps = useAvatarStyle({
    name,
    size,
    showBorder,
    borderColor,
  });
  // const hasLoaded = useHasImageLoaded({ src: src || "" });
  const hasLoaded = false;

  const theme = useTheme();
  const sizeKey = avatarSizes[size];
  const _size = theme.sizes[sizeKey];
  const fontSize = `calc(${_size} / 2.5)`;

  const renderChildren = () => {
    if (src && hasLoaded) {
      return (
        
      );
github chakra-ui / chakra-ui / packages / chakra-ui / src / Icon / Icon.tsx View on Github external
const Icon = React.forwardRef(function Icon<p>(
  {
    size = "1em",
    name,
    color = "currentColor",
    role = "presentation",
    focusable = "false",
    ...rest
  }: IconProps</p><p>,
  ref: React.Ref,
) {
  const { icons } = useTheme();

  // Fallback in case you pass the wrong name
  const iconFallback = icons["question-outline"];
  let path: JSX.Element = ;
  let viewBox = "0 0 24 24";

  if (name) {
    path = icons[name] == null ? iconFallback.path : icons[name].path;

    viewBox =
      (icons[name] == null ? iconFallback.viewBox : icons[name].viewBox) ||
      "0 0 24 24";
  }

  return (
    </p>
github chakra-ui / chakra-ui / packages / chakra-ui-system / src / create-chakra.tsx View on Github external
const Comp = (props: any, ref: React.Ref) =&gt; {
    const theme = useTheme();
    const componentTheme = theme[__themeKey as keyof Theme];

    let styleProps: Record = {};

    // constraints. We'll only allow variant, variantColor and size to be theme-aware
    const themeable = ["__size", "__variant", "__variantColor"];

    for (const key of themeable) {
      // Get the component style for any of the themeable props
      const themedStyle =
        componentTheme &amp;&amp;
        componentTheme[key] &amp;&amp;
        componentTheme[key][(props as any)[key]];

      styleProps = {
        ...styleProps,
github chakra-ui / chakra-ui / packages / chakra-ui / src / CircularProgress / CircularProgress.tsx View on Github external
size = "48px",
    max = 100,
    min = 0,
    isIndeterminate,
    thickness = 0.2,
    value = 0,
    angle = 0,
    capIsRound,
    children,
    trackColor = "gray",
    color = "blue",
    ...rest
  }: CircularProgressProps,
  ref: React.Ref,
) {
  const { colorMode } = useColorMode();

  const _trackColor = { light: `${trackColor}.100`, dark: "whiteAlpha.300" };
  const _color = { light: `${color}.500`, dark: `${color}.200` };

  const {
    rootProps,
    indicatorCircleProps,
    svgProps,
    trackCircleProps,
  } = getComputedProps({
    min,
    max,
    value,
    size,
    angle,
    thickness,
github chakra-ui / chakra-ui / packages / chakra-ui / src / Kbd / Kbd.tsx View on Github external
const Kbd = React.forwardRef(function Kbd(
  props: BoxProps,
  ref: React.Ref,
) {
  const { colorMode } = useColorMode();
  const bg = { light: "gray.100", dark: "whiteAlpha.50" };
  return (
github chakra-ui / chakra-ui / packages / chakra-ui / src / FormErrorMessage / FormErrorMessage.tsx View on Github external
const FormErrorMessage = forwardRef(function FormErrorMessage(
  props: FormErrorMessageProps,
  ref: React.Ref,
) {
  const { colorMode } = useColorMode();
  const formControl = useFormControl(props);

  const color = {
    light: "red.500",
    dark: "red.300",
  };

  if (!formControl.isInvalid) {
    return null;
  }

  return (
github chakra-ui / chakra-ui / packages / chakra-ui / src / InputAddon / InputAddon.tsx View on Github external
const InputAddon = forwardRef(function InputAddon(
  { placement = "left", size = "md", ...props }: InputAddonProps,
  ref: React.Ref,
) {
  const { colorMode } = useColorMode();
  const bg = { dark: "whiteAlpha.300", light: "gray.100" };
  const _placement = {
    left: {
      mr: "-1px",
      roundedRight: 0,
      borderRightColor: "transparent",
    },
    right: {
      order: 1,
      roundedLeft: 0,
      borderLeftColor: "transparent",
    },
  };

  type Placements = keyof typeof _placement;
github chakra-ui / chakra-ui / packages / chakra-ui / src / Alert / styles.ts View on Github external
export function useAlertIconStyle({
  variant,
  color,
}: Required) {
  const { colorMode } = useColorMode();
  if (["left-accent", "top-accent", "subtle"].includes(variant)) {
    let result = {
      light: { color: `${color}.500` },
      dark: { color: `${color}.200` },
    };

    return result[colorMode];
  }
}
github chakra-ui / chakra-ui / packages / chakra-ui / src / Checkbox / Checkbox.tsx View on Github external
isFullWidth,
    size = "md",
    isDisabled,
    isInvalid,
    onChange,
    onBlur,
    onFocus,
    isIndeterminate,
    children,
    iconColor,
    iconSize = "10px",
    ...rest
  }: CheckboxProps,
  ref: React.Ref,
) {
  const { colorMode } = useColorMode();
  const styleProps = checkboxStyles({ color: variantColor, size, colorMode });

  /**
   *
   * TODO: Improve API to be more declarative
   * 
   *   
   *   Welcome home
   * 
   */

  return (