Docs
โš™๏ธ โ Utils
useComponentTheme

useComponentTheme hook

The useComponentTheme is a hook that allows developers to get theme of a component. It also allows developers to override the default theme of a component by passing a custom theme.

Examples

In the below example, we are using useComponentTheme hook to get the theme of a button component. The Button actually passes customTheme prop to the useComponentTheme hook to override the default theme. If no customTheme is passed, the default theme is used.

import { useComponentTheme } from 'reablocks';
 
function Button({ customTheme }) {
  const theme = useComponentTheme('button', customTheme);
 
  return (
    <button className={theme.button}>
      Hello World
    </button>
  );
}

API

ParameterType
componentT
customTheme{ arrow: ArrowTheme; avatar: AvatarTheme; avatarGroup: AvatarGroupTheme; badge: BadgeTheme; block: BlockTheme; breadcrumbs: BreadcrumbsTheme; button: ButtonTheme; calendar: CalendarTheme; calendarRange: CalendarRangeTheme; card: CardTheme; checkbox: CheckboxTheme; chip: ChipTheme; collapse: CollapseTheme; commandPalette: CommandPaletteTheme; contextMenu: ContextMenuTheme; dateFormat: DateFormatTheme; dialog: DialogTheme; divider: DividerTheme; dotsLoader: DotsLoaderTheme; drawer: DrawerTheme; ellipsis: EllipsisTheme; input: InputTheme; jsonTree: JsonTreeTheme; kbd: KbdTheme; list: ListTheme; menu: MenuTheme; notification: NotificationTheme; pager: PagerTheme; popover: PopoverTheme; radio: RadioTheme; range: RangeTheme; redact: RedactTheme; select: SelectTheme; sort: SortTheme; stack: StackTheme; stepper: StepperTheme; tabs: TabsTheme; textarea: TextareaTheme; toggle: ToggleTheme; tooltip: TooltipTheme; tree: TreeTheme; typography: TypographyTheme; verticalSpacer: VerticalSpacerTheme }[T]
Source: https://github.com/reaviz/reablocks/blob/633b1c9cc185a4574b4422dfa0757cda146002c0/src/utils/Theme/hooks/useComponentTheme.ts#L10