0.3.3 • Published 15 days ago

svelte-wordpress-components v0.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
15 days ago

Svelte Wordpress Components

This is a collection of Svelte components, primarily useful for Wordpress admin pages.

Usage

<script>
import { Button } from 'svelte-wordpress-components';
function handleClick() {
    alert('Clicked!');
}
</script>

<Button on:click={handleClick} primary={true} href="/">Click me!</Button>

Components

NameDescriptionIndividual Component
AlertAn alert.Alert.svelte
ButtonA button.Button.svelte
FormInputA form input.FormInput.svelte
FormTableA form table.FormTable.svelte
ListTableA list table.ListTable.svelte

Missing a component? Ask for it, or send me a pull request.

Alert

<script>
import { Alert } from 'svelte-wordpress-components';
</script>

<Alert type="success">Success!</Alert>

Props

NameTypeDefaultDescription
typestring'info'The type of alert. Can be 'info', 'success', 'warning', or 'error'.
dismissiblebooleanfalseWhether the alert can be dismissed.
display_iconbooleantrueWhether to display an icon.
classstringnullThe classes of the alert.

Button

<script>
import { Button } from 'svelte-wordpress-components';
</script>

<Button primary={true} href="/">Click me!</Button>

Props

NameTypeDefaultDescription
primarybooleanfalseWhether the button is a primary button.
titlestringnullThe title of the link.
typestring'button'The type of button. Can be 'button', 'submit', or 'reset'.
idstringnullThe ID of the button.
classstring'button'The classes of the button.
disabledbooleanfalseWhether the button is disabled.
aria_labelstringnullThe aria-label of the button.
aria_hiddenbooleanfalseWhether the button is aria-hidden.
largebooleanfalseWhether the button is large.
smallbooleanfalseWhether the button is small.
warningbooleanfalseWhether the button is a warning button.
dangerbooleanfalseWhether the button is a danger button.
linkbooleanfalseWhether the button is a link.

FormInput

<script>
import { FormInput } from 'svelte-wordpress-components';
</script>

<FormInput label="Name" name="name" value="John Doe" />

Props

NameTypeDefaultDescription
idstringnullThe ID of the input.
namestringnullThe name of the input.
labelstringnullThe label of the input.
typestring'text'The type of input. Can be 'text', 'email', 'password', 'number', 'url', 'tel', 'date', 'time', 'datetime-local', 'month', 'week', 'color', 'checkbox', 'radio', 'textarea', 'select', 'file', or 'hidden'.
valuestringnullThe value of the input.
valuesarray[]The values of radio and checkbox input.
descriptionstringnullA description of the input that will display below the input.
classstringnullThe classes of the alert.
placeholderstringnullThe placeholder of the input.
requiredbooleanfalseWhether the input is required.
readonlybooleanfalseWhether the input is readonly.
disabledbooleanfalseWhether the input is disabled.
optionsarray[]The options of a checkbox, radio or select input.
multiplebooleanfalseWhether a select input takes multiple options.
checkedbooleanfalseWhether a checkbox input is checked.
minstringnullThe min of a number input.
maxstringnullThe max of a number input.
stepstringnullThe step of a number input.
patternstringnullThe pattern of the input.
rowsstringnullThe rows of a textarea input
colsstringnullThe cols of a textarea input.
wrapstringnullWhether to wordwrap a textarea input.

Form Table

NOTE: Previously called Form

<script>
import { FormTable, FormInput } from 'svelte-wordpress-components';
</script>

<FormTable>
    <FormInput label="Name" name="name" value="John Doe" />
</FormTable>

Props

NameTypeDefaultDescription
classstringnullThe classes of the alert.
idstringnullThe ID of the form.

ListTable

A list table creates a table similar to a WP_List_Table.

<script>
import { ListTable } from 'svelte-wordpress-components';
const headers = [
        {
            name: "select",
            key: "select",
            type: "select",
        },
        {
            name: "Name",
            key: "link_name",
            type: "unsafe",
        },
        {
            name: "Created",
            key: "createdAt",
            type: "date",
        },
        {
            name: "Active",
            key: "active",
            type: "boolean",
        },
    ]
const data = [
        {
            select: true,
            link_name: '<a href="#">John Doe</a>',
            createdAt: '2020-01-01',
            active: true,
        },
        {
            select: false,
            link_name: '<a href="#">Jane Doe</a>',
            createdAt: '2020-01-01',
            active: false,
        },
    ]

</script>

<ListTable {headers} {data} />

Props

NameTypeDefaultDescription
headersarray[]The headers of the table.
dataarray[]The data of the table.

Header

NameTypeDefaultDescription
namestringnullThe name of the header.
keystringnullThe key of the header.
typestringnullThe type of the header. Can be 'select', 'image', 'text', 'link', 'date', 'number', 'boolean', or 'unsafe' (does not escape HTML).
0.3.0

15 days ago

0.3.2

15 days ago

0.3.1

15 days ago

0.3.3

15 days ago

0.1.0

7 months ago

0.1.1

7 months ago

0.0.1

8 months ago