Franken UI

repository·master·Indexed 25 days ago

https://github.com/franken-ui/ui

An HTML-first UI component library built on UIkit 3 and extended with LitElement, inspired by shadcn/ui. It integrates with Tailwind CSS and PostCSS, providing a CLI for configuration, a Tailwind CSS plugin for theme extensions, and a wide range of components including form elements, layout utilities, and interactive widgets. Version 2.1.2-next.0 supports custom color palettes and a flexible extension system to modify the global theme, base styles, and component configurations.

Tokens
1.8K
Snippets
1
Records
13
Agent score
83%

What's inside franken-ui

  1. Understand the Context object structure

    master

    The Context object is the final output of the Franken UI generation process. It contains all the CSS rules organized by their purpose. It consists of:

    • theme: Contains :root and .dark CSS rule objects for global theme variables.
    • base: A collection of base CSS rules.
    • palettes: CSS rules associated with defined color palettes.
    • components: A collection of Components, where each component contains its own CSSRuleObjects.
  2. Configure plugin extensions

    master

    The Franken UI plugin allows you to extend its core functionality using the extensions option. This is useful for overriding themes, adding custom palettes, or modifying component styles during the plugin's execution lifecycle.

    An extension is an array of tuples: [plugin, config]. The plugin must be a function with the signature (context: Context, config: any) => Context. The context object contains:

    • theme: The base theme configuration.
    • base: Base CSS rules.
    • palettes: Generated color palettes.
    • components: Component-specific CSS rules.

    By returning a modified context, your extension can influence the final CSS generated by addBase and addComponents.

  3. Use the Franken UI Tailwind CSS plugin

    master

    Franken UI is distributed as a Tailwind CSS plugin. You can initialize it in your tailwind.config.js file. The plugin accepts an optional options object which can include extensions to modify the internal context (theme, base, palettes, and components) before the CSS rules are generated.

    To use the plugin, import it and add it to your plugins array. If you provide extensions, each extension is a function that receives the current Context and a configuration object, returning a modified Context.

  4. Configure Franken UI via the Options interface

    master

    The Options type defines the configuration available when initializing Franken UI. You can control CSS preflight, layer injection, and provide custom color palettes or extensions.

    Key options:

    • preflight: Boolean to enable/disable CSS reset/preflight.
    • layer: Boolean to wrap styles in a CSS layer.
    • layerExceptions: An array of strings representing CSS layers that should be excluded from the layer wrapping.
    • customPalette: A Palette object used to override default theme colors.
    • extensions: An array of Extensions to modify the generated Context.
  5. Generate custom color palettes with palettes()

    master

    The palettes function generates a CSSRuleObject containing color variables based on a provided configuration. You can use it to create a custom theme by passing a customPalette object within the options argument. This object will be merged with the default variables.

    To use it, call palettes({ customPalette: { ... } }). The resulting object can then be applied to your CSS to define the color scheme for your application.

  6. Extend Franken UI using Extensions

    master

    An Extension is a function that allows you to intercept and modify the generated Context. This is useful for adding custom components, modifying existing CSS rules, or injecting new theme variables.

    An extension follows this signature: (context: Context, config: ExtensionConfig) => Context

    To use extensions, pass them in the extensions field of the Options object as an array of tuples, where each tuple contains the extension function and its specific configuration object.

    Extensions format: [Function, ExtensionConfig][]

  7. Access the default theme and component configurations

    master

    The context.ts module exports several pre-configured objects that define the visual identity of Franken UI:

    • theme: Contains the default :root and .dark CSS rules for the global theme.
    • base: Contains base typography settings (like fontSize and lineHeight for the body) and global focus-visible styles.
    • components: A Components object containing the CSS rule configurations for all supported UI components (e.g., accordion, button, card, modal, tab, etc.).
  8. Import components from franken-ui

    master
    The franken-ui component library provides a wide range of UI components exported from a single entrypoint. You can import these components directly from the library to build your interface. The components are categorized into form elements, layout utilities, and interactive widgets.
  9. Available Franken UI color themes

    master

    Franken UI provides several built-in color themes via CSS variables. Each theme includes both a light mode and a dark mode (prefixed with .dark.). Themes are applied by adding the corresponding class to a parent element (e.g., uk-theme-zinc).

    Available themes:

    • uk-theme-zinc
    • uk-theme-slate
    • uk-theme-stone
    • uk-theme-gray
    • uk-theme-neutral
    • uk-theme-red
    • uk-theme-rose
    • uk-theme-orange
    • uk-theme-green
    • uk-theme-blue
    • uk-theme-yellow
    • uk-theme-violet
    • uk-theme-amber
    • uk-theme-purple
    • uk-theme-teal
  10. Reference: Franken UI init CLI flags

    master

    The following flags are available for the initialization command:

    FlagShortDescription
    --postcss-pCreates a postcss.config.cjs file in addition to the Tailwind config.
    --force-f(Note: While defined in the mapping, the current implementation primarily checks for existing files and errors if they exist rather than overwriting).
  11. Define custom color palettes using the Colors type

    master

    The Colors type defines the set of CSS variables used for theming. When providing a customPalette, you can map theme names to a Colors object containing these specific keys:

    • --background / --foreground
    • --muted / --muted-foreground
    • --popover / --popover-foreground
    • --card / --card-foreground
    • --border
    • --input
    • --primary / --primary-foreground
    • --secondary / --secondary-foreground
    • --accent / --accent-foreground
    • --destructive / --destructive-foreground
    • --ring

    Legacy compatibility keys include --destructive-alpha, --border-alpha, and --input-alpha.

    type Colors = {
    	'--background': string;
    	'--foreground': string;
    	'--muted': string;
    	'--muted-foreground': string;
    	'--popover': string;
    	'--popover-foreground': string;
    	'--card': string;
    	'--card-foreground': string;
    	'--border': string;
    	'--input': string;
    	'--primary': string;
    	'--primary-foreground': string;
    	'--secondary': string;
    	'--secondary-foreground': string;
    	'--accent': string;
    	'--accent-foreground': string;
    	'--destructive': string;
    	'--destructive-foreground': string;
    	'--ring': string;
    
    // For compatibility with legacy colors
    	'--destructive-alpha'?: string;
    	'--border-alpha'?: string;
    	'--input-alpha'?: string;
    };