🎨
Valence
🎨
Valence
  • Overview
    • 👋Welcome to Valence
    • 🏄‍♂️Getting started
  • Core Concepts
    • Responsiveness
    • Color
      • List of colors
      • Color types
    • Polymorphism
  • Valence Core
    • 🏃‍♂️Fundamentals
      • 🎬The ValenceProvider
      • ✍️Using custom fonts
    • 🧱Components
      • 🔘Buttons
        • Button with icon
        • Grid Button
        • Text button
        • Icon button
        • Multi-part button
        • Unstyled button
        • Primitive button
      • ⌨️Inputs
        • Color Picker
        • Text input
        • Text area
        • Number input
        • Select input
        • Switch
        • Slider
        • Range slider
        • Pill selector
        • Input container
        • Dropdown container
      • 🖥️Display
        • Accordion
        • Alert
        • Color Swatch
        • Icon
        • Image
        • Avatar
        • Avatar Group
        • Loader
        • Pill
        • Spoiler
        • Stepper
        • Text
        • Title
      • 🧩Layout
        • App Container
        • Card
        • Flex
          • Flex Center
          • Styled Flex
        • Floating Toolbar
        • Grid
        • Header
        • Overflow Container
        • Space
      • 🗺️Navigation
        • App Nav
      • 🔼Overlays
        • Modal
        • Tooltip
        • Modal background
        • 📰Sheets
          • Bottom Sheet
          • Dynamic Sheet
          • Side Sheet
    • 🪝Hooks
      • UseColorScheme
      • UseColors
      • UseControlledList
      • UseDetectKeyDown
      • UseDisclosure
      • UseFloating
      • UseTooltip
      • UseBreakpoint
      • UseResponsiveProps
    • 🤚Generics
      • Generic button props
      • Generic input props
      • Generic Sheet Props
  • Valence Plugins
    • 🎠Valence Carousel
      • Carousel Child Props
  • Valence Utils
    • ✋Generics
      • Clickable
      • Events
      • Global
      • Grid
      • Layout
      • Overlay
      • Polymorphic
    • 🧜‍♀️Polymorphism
      • Polymorphic Button
      • Polymorphic Layout
      • Polymorphic Text
  • Update Notes
    • 3.0.0
    • 2.7.0
    • 2.6.0
    • 2.5.0
    • 2.4.0
    • 2.3.0
    • 2.2.0
    • 2.1.0
    • 2.0.0
Powered by GitBook
On this page
  • Usage
  • Return type
  • Changelog

Was this helpful?

Edit on GitHub
  1. Valence Core
  2. Hooks

UseColors

Last updated: 2.7.0 (16/06/2024)

PreviousUseColorSchemeNextUseControlledList

Last updated 12 months ago

Was this helpful?

This hook forms part of the . For more information about how this system works, see .

useColors is a hook that allows the usage of Valence colors in any component. All components must be a child of the ValenceProvider to function correctly.

Usage

import { useColors, Button } from "@valence-ui/core";
import { CSSProperties } from "react";

function MyComponent() { 
    const { getHex } = useColors();

    const buttonStyle: CSSProperties = { 
        color: getHex("blue", "weak"),
    }
    
    return ( 
        <Button
            style={buttonStyle}
        >
            I'm a button!
        </Button>
    )
}

Return type

Attribute
Type
Description

getSwatch

Gets the swatch for the given color key. If the color does not exist, this will return undefined.

getHex

Gets the hex code for the given color key. If the color does not exist, this will return the key as-is.

getBgHex

(key: string, variant?: FillVariant, hovered?: boolean): string | undefined

Gets the most suitable background color, based upon the supplied parameters.

getBorderHex

(key: string, variant?: FillVariant, focused?: boolean)

Gets the most suitable border color, based upon the supplied parameters.

getFgHex

(key: string, variant?: FillVariant): string | undefined

Gets the most suitable foreground color, based upon the supplied parameters.

Changelog

  • 2.7.0: added the getBorderHex method.

(key: string | undefined): | undefined

(key: string | undefined, opacity?: ): string | undefined

🪝
Color utility system
Color
Swatch
SwatchOpacity