Segmented control is a linear set of two or more segments (buttons), each of which functions as a mutually exclusive button. Within the control, all buttons are equal in width. Segmented controls are often used to display different views (switch tabs).
There are following components included:
Segmented - segmented wrapper for buttonsSegmentedButton - single segmented button| Name | Type | Default | Description |
|---|---|---|---|
| colors | object | Object with Tailwind CSS colors classes | |
| colors.borderIos | string | 'border-primary' | |
| colors.borderMaterial | string | 'border-md-light-outline dark:border-md-dark-outline' | |
| colors.divideIos | string | 'divide-primary' | |
| colors.divideMaterial | string | 'divide-md-light-outline dark:divide-md-dark-outline' | |
| colors.strongBgIos | string | 'bg-black/5 dark:bg-white/10' | |
| colors.strongBgMaterial | string | 'bg-md-light-surface-variant dark:bg-md-dark-surface-variant' | |
| colors.strongHighlightBgIos | string | 'bg-white dark:bg-white/75' | |
| colors.strongHighlightBgMaterial | string | 'bg-white dark:bg-white/15' | |
| component | string | 'div' | Component's HTML Element |
| outline | boolean | false | Makes segmented outline |
| outlineIos | boolean | false | Makes segmented outline in iOS theme |
| outlineMaterial | boolean | false | Makes segmented outline in Material theme |
| raised | boolean | false | Makes segmented raised |
| raisedIos | boolean | false | Makes segmented raised in iOS theme |
| raisedMaterial | boolean | false | Makes segmented raised in Material theme |
| rounded | boolean | false | Makes segmented rounded |
| roundedIos | boolean | false | Makes segmented rounded in iOS theme |
| roundedMaterial | boolean | false | Makes segmented rounded in Material theme |
| strong | boolean | false | Makes segmented strong |
| strongIos | boolean | false | Makes segmented strong in iOS theme |
| strongMaterial | boolean | false | Makes segmented strong in Material theme |
SegmentedButton component extends Button component, it supports all Button props and the following additional props:
| Name | Type | Default | Description |
|---|---|---|---|
| active | boolean | false | Highlights button as active |
| component | string | 'button' | Component's HTML Element |
import React, { useState } from 'react';import {Page,Navbar,NavbarBackLink,Segmented,SegmentedButton,Block,BlockTitle,} from 'konsta/react';export default function SegmentedControlPage() {const [activeSegmented, setActiveSegmented] = useState(1);return (<Page><Navbartitle="Segmented Control"/><BlockTitle>Default Segmented</BlockTitle><Block strong inset className="space-y-4"><Segmented><SegmentedButtonactive={activeSegmented === 1}onClick={() => setActiveSegmented(1)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 2}onClick={() => setActiveSegmented(2)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 3}onClick={() => setActiveSegmented(3)}>Button</SegmentedButton></Segmented><Segmented rounded><SegmentedButtonactive={activeSegmented === 1}onClick={() => setActiveSegmented(1)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 2}onClick={() => setActiveSegmented(2)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 3}onClick={() => setActiveSegmented(3)}>Button</SegmentedButton></Segmented></Block><BlockTitle>Raised Segmented</BlockTitle><Block strong inset className="space-y-4"><Segmented raised><SegmentedButtonactive={activeSegmented === 1}onClick={() => setActiveSegmented(1)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 2}onClick={() => setActiveSegmented(2)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 3}onClick={() => setActiveSegmented(3)}>Button</SegmentedButton></Segmented><Segmented raised rounded><SegmentedButtonactive={activeSegmented === 1}onClick={() => setActiveSegmented(1)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 2}onClick={() => setActiveSegmented(2)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 3}onClick={() => setActiveSegmented(3)}>Button</SegmentedButton></Segmented></Block><BlockTitle>Outline</BlockTitle><Block strong inset className="space-y-4"><Segmented outline><SegmentedButtonactive={activeSegmented === 1}onClick={() => setActiveSegmented(1)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 2}onClick={() => setActiveSegmented(2)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 3}onClick={() => setActiveSegmented(3)}>Button</SegmentedButton></Segmented><Segmented rounded outline><SegmentedButtonactive={activeSegmented === 1}onClick={() => setActiveSegmented(1)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 2}onClick={() => setActiveSegmented(2)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 3}onClick={() => setActiveSegmented(3)}>Button</SegmentedButton></Segmented></Block><BlockTitle>Strong Segmented</BlockTitle><Block strong inset className="space-y-4"><Segmented strong><SegmentedButtonactive={activeSegmented === 1}onClick={() => setActiveSegmented(1)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 2}onClick={() => setActiveSegmented(2)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 3}onClick={() => setActiveSegmented(3)}>Button</SegmentedButton></Segmented><Segmented strong rounded><SegmentedButtonactive={activeSegmented === 1}onClick={() => setActiveSegmented(1)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 2}onClick={() => setActiveSegmented(2)}>Button</SegmentedButton><SegmentedButtonactive={activeSegmented === 3}onClick={() => setActiveSegmented(3)}>Button</SegmentedButton></Segmented></Block></Page>);}