This repository has been archived by the owner on Aug 1, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): SegmentedControl component (#377)
See: https://developer.apple.com/design/human-interface-guidelines/ios/controls/segmented-controls/ *** * Fix comment * Update ui/DesignSystem/Component/SegmentedControl.svelte Co-authored-by: Julien Donck <julien@monadic.xyz> * Use event dispatcher * Only show active when not hovered Co-authored-by: Rūdolfs Ošiņš <rudolfs@osins.org> Co-authored-by: Julien Donck <julien@monadic.xyz>
- Loading branch information
1 parent
fbc7016
commit 6c92ebd
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script> | ||
import { createEventDispatcher } from "svelte"; | ||
const dispatch = createEventDispatcher(); | ||
// Currently active option. | ||
export let active = null; | ||
// The available options. | ||
export let options = null; | ||
const onClick = (option) => { | ||
dispatch("select", option); | ||
currentlyActive = option.value; | ||
}; | ||
$: currentlyActive = active; | ||
</script> | ||
|
||
<style> | ||
.segmented-control { | ||
display: flex; | ||
} | ||
.segmented-control:hover button.active:not(:hover) { | ||
background: none; | ||
} | ||
.segmented-control button { | ||
cursor: pointer; | ||
padding: 8px 16px; | ||
border-radius: 4px; | ||
margin: 0; | ||
background-color: var(--color-background); | ||
color: var(--color-foreground-level-6); | ||
font-family: var(--typeface-medium); | ||
} | ||
.segmented-control button:focus { | ||
outline: none; | ||
} | ||
.segmented-control button.active { | ||
background-color: var(--color-foreground-level-1); | ||
color: var(--color-secondary); | ||
} | ||
.segmented-control button:hover { | ||
background-color: var(--color-foreground-level-1); | ||
} | ||
.segmented-control button:active { | ||
background-color: var(--color-foreground-level-1); | ||
color: var(--color-secondary-level-2); | ||
} | ||
</style> | ||
|
||
<div class="segmented-control"> | ||
{#each options as option} | ||
<button | ||
class:active={option.value === currentlyActive} | ||
value={option.value} | ||
on:click={() => onClick(option)}> | ||
{option.title} | ||
</button> | ||
{/each} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters