Button

Lockness UI Component

VIEW

DOCUMENTATION

Button

Flexible button component with multiple variants and sizes, featuring full Unpoly integration for SPA-like navigation.

Installation

bash
deno run -A jsr:@lockness/ui add button

Usage

tsx
import { Button } from '@lockness/ui/components'

<Button variant="primary">Click me</Button>

Variants

The Button component supports multiple visual styles:

  • primary: Main action button (default)
  • secondary: Secondary actions
  • outline: Bordered with transparent background
  • ghost: Minimal styling with hover effect
  • danger: Destructive actions (delete, remove)

Sizes

Available sizes for different use cases:

  • xl: Extra large
  • lg: Large
  • md: Medium (default)
  • sm: Small

Unpoly Props

Props for configuring Unpoly behavior:

PropTypeDescription
hrefstringRenders as anchor with up-follow
preloadbooleanPreload page on hover
targetUnpolyTargetCSS selector to update
transitionUnpolyTransitionTransition animation
durationnumberTransition duration in ms
easingUnpolyEasingCSS timing function
failTransitionUnpolyTransitionTransition on server error

Transitions

Available Unpoly transitions:

ValueDescription
cross-fadeSimultaneous fade old/new
move-leftSlide left (forward nav)
move-rightSlide right (back nav)
move-upSlide up
move-downSlide down
noneNo animation

Targets

Special selectors for the target prop:

ValueDescription
:mainMain content area
:layerCurrent layer (modal, popup)
:originElement that triggered action
:noneNo element (request only)

Easing Functions

CSS timing functions for the easing prop:

ValueDescription
linearConstant speed
easeSlow start, fast, slow end
ease-inSlow start
ease-outSlow end
ease-in-outSlow start and end

Examples

Basic Buttons

tsx
<Button variant="primary">Primary</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="danger">Delete</Button>
<Button disabled>Disabled</Button>

Button Sizes

tsx
<Button size="xl" variant="primary">Extra Large</Button>
<Button size="lg" variant="primary">Large</Button>
<Button size="md" variant="primary">Medium</Button>
<Button size="sm" variant="primary">Small</Button>

Link Buttons with Unpoly

tsx
<Button href="/users" target=":main">View Users</Button>
<Button href="/dashboard" preload transition="cross-fade">Dashboard</Button>
<Button href="/settings" target=".content" transition="move-left">Settings</Button>

Custom Styling

tsx
<Button class="w-full">Full Width</Button>
<Button variant="outline" class="border-2 border-primary">Custom Border</Button>

Theming

The Button component can be customized using CSS variables. This allows you to change the appearance of buttons globally or override specific instances.

Available CSS Variables

VariableDefaultDescription
--button-border-radiusvar(--radius)Button border radius
--button-border-width0pxBorder width for all variants
--button-border-width-outline2pxBorder width for outline
--button-font-weight500Button font weight
--button-transition-duration150msTransition animation speed
--button-disabled-opacity0.6Opacity when disabled
--button-shadownoneDefault box shadow
--button-shadow-hovernoneBox shadow on hover
--button-shadow-focus0 0 0 2px var(--ring)Focus ring shadow
--button-padding-x-sm0.75remHorizontal padding (small)
--button-padding-y-sm0.375remVertical padding (small)
--button-font-size-sm0.875remFont size (small)
--button-padding-x-mdcalc(...)Horizontal padding (medium)
--button-padding-y-mdcalc(...)Vertical padding (medium)
--button-font-size-mdcalc(...)Font size (medium)
--button-padding-x-lgcalc(...)Horizontal padding (large)
--button-padding-y-lgcalc(...)Vertical padding (large)
--button-font-size-lgcalc(...)Font size (large)
--button-padding-x-xlcalc(...)Horizontal padding (x-large)
--button-padding-y-xlcalc(...)Vertical padding (x-large)
--button-font-size-xlcalc(...)Font size (x-large)

Theming Examples

Global Customization

Customize all buttons by setting CSS variables in your theme:

css
/* app/view/assets/app.css */
@theme {
    /* Make buttons more rounded */
    --button-border-radius: 0.5rem;

    /* Add shadows to buttons */
    --button-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    --button-shadow-hover: 0 4px 6px rgba(0, 0, 0, 0.1);

    /* Make buttons bolder */
    --button-font-weight: 600;

    /* Increase padding for all sizes */
    --button-padding-x-sm: 1rem;
    --button-padding-y-sm: 0.5rem;
}

Local Overrides

Override CSS variables for specific button instances:

tsx
<div style="--button-border-radius: 9999px;">
    <Button variant="primary">Pill Button</Button>
</div>

<div style="--button-shadow-hover: 0 10px 20px rgba(0,0,0,0.2);">
    <Button variant="primary">Dramatic Hover</Button>
</div>

Component-Specific Theming

Create themed sections with different button styles:

tsx
<section class="premium-section">
    <style>
        .premium-section {
            --button-border-radius: 0.25rem;
            --button-font-weight: 700;
            --button-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
    </style>
    <Button variant="primary">Premium Action</Button>
</section>

VARIANTS

tsx
import { Button } from '@lockness/ui/components'

<Button variant='primary'>Primary</Button>
<Button variant='secondary'>Secondary</Button>
<Button variant='outline'>Outline</Button>
<Button variant='ghost'>Ghost</Button>
<Button variant='danger'>Danger</Button>
<Button disabled>Disabled</Button>

SIZES

tsx
<Button size='xl'>Extra Large</Button>
<Button size='lg'>Large</Button>
<Button size='md'>Medium</Button>
<Button size='sm'>Small</Button>