These templates are yours to grab and modify as you need!
Just copy the source code & paste into a new .svelte file.
These can do basic color theming, if you set the css variables in a parent component:
:root {
--accent-color: #3E3454;
--gray: #ccc;
}
If you don't define an --accent-color and --gray, the accent defaults to #282828 and gray defaults to #ccc.
Whenever possible, component code is available both with opinionated styling (e.g., animations, rounded corners etc.) and without it. Choose whichever better suits your purpose!
UI Elements
Component Description
A component to create a single checkbox or group of checkboxes. These should be used when a user can select more than one item out of a group of options or to turn a single feature on or off.
Bindable value for accessing selected checkbox values
fontSize
number
Size of checkbox and text, defaults to 16
flexDirection
row or column
Indicator of which direction the checkboxes should be visually arranged
Bound Values
This component exposes the variable value to the parent component. An array of selected check values can be accessed in the parent component using bind:value
Bindable value for accessing selected radio button value
fontSize
number
Size of radio button and text, defaults to 16
flexDirection
row or column
Indicator of which direction the checkboxes should be visually arranged
Bound Values
This component exposes the variable userSelected to the parent component. An array of selected radio values can be accessed in the parent component using bind:userSelected
This component is keyboard and screen-reader accessible by default. TAB to select element, Arrow Keys to toggle between radio buttons.
Component Description
A component to create a single toggle switch (with 3 style options). The Inner or Slider design options should be used when a user can toggle an option between an on or off (or any other binary) state. The Multi design option should be used when the user is toggling between two possible options that are not binary.
Brief description of the group of the toggle switch
design
inner, slider, or multi
Indicator of which style of toggle switch should be drawn
options
array of strings
Only necessary for "multi" design option
value
string
Bindable value for accessing selected switch value
fontSize
number
Size of switch and text, defaults to 16
Bound Values
This component exposes the variable userSelected to the parent component. An array of selected radio values can be accessed in the parent component using bind:userSelected
Example Use
<script>importSwitchfrom'./Switch.svelte'letswitchValue;letsliderValue;letmultiValue;</script><Switchbind:value={switchValue}label="Enable dark mode"design="inner" /><p>Switch is {switchValue}</p><Switchbind:value={sliderValue}label="Enable dark mode"fontSize={24}design="slider" /><p>Switch is {sliderValue}</p><Switchbind:value={multiValue}label="Choose a theme"design="multi"options={['light', 'dark']}fontSize={12}/><p>Switch is {multiValue}</p>
Accessibility
These components are keyboard and screen-reader accessible by default. On the back-end, the Inner and Slider designs are switch elements. You can TAB to the element and press either SPACE or ENTER to toggle. The Multi design, is a series of radio buttons, and thus can be accessed via TAB and toggled with Arrow keys.
Component Description
A component to create a group of UI elements designed to look like a set of buttons. These should be used when a user can select one (and only one) item out of a group of options.
Bindable value for accessing selected radio button value
fontSize
number
Size of button text, defaults to 16
Bound Values
This component exposes the variable userSelected to the parent component. A string with the selected button value can be accessed in the parent component using bind:userSelected
This component is keyboard and screen-reader accessible by default. On the back end, this is using a group of radio buttons. TAB to select element, Arrow Keys to toggle between radio buttons.
Component Description
A component to add and resize icons to other elements. All possible icons can be viewed on the Feather Icons Site.
This component hasn't been evaluated for accessibility concerns.
Component Description
A component to add an autocomplete search bar. These can be helpful when there are many options in a select menu, and you want to keep your users from needing to scroll endlessly.
⚠️ This component also requires the Icon.svelte component (not automatically copied from the above buttons).
Examples
Bulbasaur
Charmander
Charmeleon
Ivysaur
Squirtle
Wartortle
6 results available
Props
This component takes 5 props:
Prop
Expects
Description
data
array of objects
Data to fill autocomplete. Expects both value and label variables
name
string
Label for the autocomplete search box
fontSize
number
Size of search box and text, defaults to 16
selected
string
Bindable element returning the value of the selected option
clearButton
boolean
Whether to generate a button to clear the input of the autocomplete, defaults to true
Bound Values
This component exposes the variable selected to the parent component. A string with the selected button value can be accessed in the parent component using bind:selected
This component is keyboard and screen-reader accessible by default. Users can TAB to select the input element, use their Arrow Keys to move up and down the rendered list of options, and Enter to select one. Pressing the Escape key closes the menu.
Pagination
Component Description
A component to create a series of circular buttons. These are, by default, presented as a way to navigate through a stepper or paginated content. Ideal for processes with a few steps where steps can be skipped.
Bindable value for accessing the selected button index
fontSize
number
Size of dots and text, defaults to 16
Bound Values
This component exposes the variable activeIndex to the parent component. A string containing the selected button's index can be accessed in the parent component using bind:activeIndex
Example Use
<script>importProgressDotsfrom'./ProgressDots.svelte'letdotValue;</script><ProgressDotsnumberOfItems={4}bind:activeIndex={dotValue}/><p>
Step {dotValue + 1} is selected.
</p>
Accessibility
This component is keyboard and screen-reader accessible by default. This component uses individual button elements for navigation, so they can each be individually accessed via TAB, and selected via SPACE or ENTER.
Component Description
A component to automaically split and paginate data or content. This can be used to paginate any sort of output, including data tables.
⚠️ This component also requires the Icon.svelte component (not automatically copied from the above buttons).
Examples
Load previous 5 rows
1 - 5 of 15
Load next 5 rows
Props
This component takes 3 props:
Prop
Expects
Description
rows
array
The data to be paginated
perPage
number
The number of items that you want to be displayed on each page
trimmedRows
array
Bindable value containing the trimmed data to be displayed for the current page
Bound Values
This component exposes the variable trimmedRows to the parent component. An array containing the trimmed data to be displayed on the selected "page" can be accessed in the parent component using bind:trimmedRows.
Example Use
<script>importPaginationfrom'./Pagination.svelte';
constexamples = 'The Pudding is a digital publication that explains ideas debated in culture with visual essays.'.split(' ')
letvalues;</script>{#if values}{#each values as value}<p>{value}</p>{/each}{/if}<Paginationrows={examples}perPage={3}bind:trimmedRows={values} />
Accessibility
This component is keyboard and screen-reader accessible by default. This component uses individual button elements for navigation, so they can each be individually accessed via TAB, and selected via SPACE or ENTER.
Page Structure
Component Description
A component to create sections of content that can be hidden (visually and to keyboards/screen readers) and made visible again. This component uses unnamed slots, so any content can be wrapped within it and hidden and made visible.
This component doesn't expose any props for binding.
Example Use
<script>importCollapsibleSectionfrom'./CollapsibleSection.svelte'</script><section><CollapsibleSectionheaderText={'Collapse or expand me!'} ><divclass="content">
Look at all this fun content
</div></CollapsibleSection><CollapsibleSectionheaderText={'I can collapse or expand too!'} ><divclass="content">
Look at all this fun content
</div></CollapsibleSection></section><style>section {
width: 400px;
}
.content {
background-color: #f4f4f4;
padding: 0.5em;
}
</style>
Accessibility
This component is keyboard and screen-reader accessible by default. This component uses a button element for navigation, so they can each be individually accessed via TAB, and selected via SPACE or ENTER. By default, this button is wrapped in an h3 element. If that isn't the next heading level for your page, it'll need to be manually changed in the component itself.
Data & Code
Component Description
A component to create sortable, semantic HTML tables.
This component uses semantic HTML tables and button elements to make it as keyboard and screen reader navigable as possible. The sort buttons can be accessed via TAB, and selected via SPACE or ENTER.
To improve accessibility even further, the data should be exported in a format that is human readable (e.g., a value of 8743804 could be exported as 8.7 million). The raw values could be retained in a second column, if preferred.
Component Description
The basics for a scatterplot. This uses svelte spring, which animates the dots on change, but requires a consistent number of items in the data array.
This component hasn't been evaluated for accessibility concerns.
Decoration
Component Description
This is a message that will pop up to give quick user feedback, and disappears after a short amount of time. The message shows up whenever the text or iteration changes. Changing the iteration is a good way to make sure the message shows up when needed, even if the text doesn't change.
A number to re-trigger before the message has disappeared
duration
number
The length of time, in milliseconds, the message remains on screen (default 1000)
Bound Values
This component doesn't expose any props for binding.
Example Use
<script>importBriefMessagefrom'./BriefMessage.svelte'letmessageIteration = 0;
letmessageDuration = 500;
letmessage = "This is the message";
</script><BriefMessagetext={message}iteration={messageIteration}duration={messageDuration} />
Accessibility
Be cautious when using this component with non-decorative content for accessibility reasons. Some users may not be able to read quickly enough to process the information before it disappears. Others may have read it and not retained the information. In its current form, screen reader or assistive technology users aren't identified of the notification at all. Find more information about ensuring these types of messages are as accessible as possible in this article.
Component Description
Displays a number with an interpolated animation when changed.