@bizmate-oss/sveltekit-components
v1.0.92
Published
Library for sveltekit components
Downloads
66
Maintainers
Readme
Sveltekit Library
Library containing Sveltekit components
Usage
npm install -D @bizmate-oss/sveltekit-components
Components
Table
Responsive table to display and filter arrays of data
Minimalistic example
<script>
import { Table } from '@bizmate-oss/sveltekit-components';
//or import Table from '@bizmate-oss/sveltekit-components/Table/Table.svelte'
let cols = [
{
id: 'firstName',
label: 'First Name',
searchable: true,
},
{
id: 'params.lastName',
label: 'Last Name'
}
]
let rows = [
{
firstName: 'Jason',
params: {
lastName: 'Smith'
}
},
{
firstName: 'John',
params: {
lastName: 'White'
}
}
]
</script>
<Table {rows} {cols} border alternateRows isExportable/>
Configuration
- id:
string
- A unique id for the table. Will be automatically generated if not provided - rows:
Array of Objects
- Array containing the data to be displayed - cols:
Array of Objeccts
- Array that describes the columns of the table. Every column object can have the following properties:- id:
string
- A unique id for identifing the column. MUST be equal to the path where the values of rows are saved, words divided by a dot. Example: to display the value of rows[n].params.data, the respective column id must be 'params.data' - label:
string
- The label that will be displayed on top of the column - datatype (optional):
string
- The datatype which will occupy such column.- Available values:
'string' | 'number' | 'date' | 'boolean' | 'enum'
. Default:'string'
- Available values:
- searchable (optional):
boolean
- Specify if a column is searchable. Default:false
- sortable (optional):
boolean
- Specify if a column is sortable. Default:true
- icon (optional):
boolean
- Specify if the column value is represented by an icon. Default:false
- min (optional):
boolean
- Specify if a column should be the smallest as possibile. Default:false
- align (optional):
string
- Align contents of the column's cells. - hidden (optional):
boolean
- Hides the column- Available values:
'center' | 'end'
. Default:undefined
(normally aligned to the left)
- Available values:
- format (optional):
function
- Function that transforms the column's respective value of rows in the desired HTML format.- Arguments: The column's row value and the row object
- Return value:
string
- id:
- title:
string
- Table's Title that will be displayed on top - pageRows:
string | number
- The number of rows to be displayed for each page. Can be changed afterwards through GUI. Default:10
- isExportable:
boolean
- Set if the Table can be exported or not.- Available formats:
'csv' | 'xls' | 'pdf'
- Available formats:
- alternateRows:
boolean
- Set if rows should be coloured with slightly different colours. Default:false
- dark:
boolean
- Enable dark theme for the table. Default:false
- border:
boolean
- Set if the table should have borders. Default:false
Select
Select with support for HTML options and selections
Example
<script>
import { Select } from '@bizmate-oss/sveltekit-components';
let options = ["Product", "sky", "Dollar", "Minivan", "San"]
const format = (opt) => {
if(opt.length <= 6){
return `<div class="text-primary">${opt}</div>`
} else {
return `<div class="text-secondary">${opt}</div>`
}
}
</script>
<Select {options} {format}/>
Configuration
- options:
Array of strings
- The available options for selection. Can beundefined
if bothdata
andpath
are defined - data:
Array of Objects
- Array containing the data from where the options can be extracted - path:
string
- Path relative to data where the options can be found N.B.: If both options and data+path are defined, the options passed will be overwritten by the ones coming from data - placeholder:
string
- Placeholder if no option is selected - format:
function
- Function that trasforms the options in the desired HTML format.- If the Select is using the property "options" to display the data, the function will be called for each option and have as an argument just the option itself.
- If the Select is extracting the options from the data, then the function will be called once for every object of data (with arguments the value of the current object in the specified path and the object itself), make values unique and then save them in the "options" variable.
- multiple:
boolean
- Allow selections of multiple options. Default:false
- width:
number
- Set the width of Select - selected:
Array | string
- The currently selected options. Will be an array ifmultiple
is set, otherwise just a string.
Auth
A component that displays slotted content within if any role of the current user matches his scope
Example
<script>
import { Auth } from '@bizmate-oss/sveltekit-components';
let user_roles = ["user", "manager"];
</script>
<Auth allow="manager,admin" roles={user_roles}>
<p>You can only see this if you're a manager or an admin</p>
</Auth>
Configuration
- allow:
string | Array of Strings
- The roles that are granted access to the slotted resorce. If using a string, concatenate multiple roles using,
- roles:
Array of Strings
- The current user roles
Navbar
Svelte configurable navbar built on bootstrap navbar, with child component NavItem Bootstrap must be installed in the project for this component to work
Example
<script>
import { Navbar, NavItem } from '@bizmate-oss/sveltekit-components';
import { page } from '$app/stores';
</script>
<Navbar {vertical} pills>
<NavItem href="/" active={$page.route.id == '/'}>Home</NavItem>
<NavItem href="/settings" active={$page.route.id.startsWith('/settings')}>Settings</NavItem>
</Navbar>
Configuration
- Navbar:
- vertical:
Boolean
- Place the navbar vertically - pills:
Boolean
- Use pills style - tabs:
Boolean
- Use tabs style - fill:
Boolean
- Fill width of container - class: - DOM classes
- style: inline style
- vertical:
- NavItem:
- href:
String
- Reference to navigation page - active:
Boolean
- If the current element is the current active element
- href:
Dropdown
Svelte configurable dropdown built on bootstrap dropdown, with child component DropdownItem Bootstrap must be installed in the project for this component to work
Example
<script>
import { Dropdown, DropdownItem } from '@bizmate-oss/sveltekit-components';
import { faker } from '@faker-js/faker';
let user = {
email: faker.internet.email(),
name: faker.name.firstName(),
tenant: faker.company.name(),
profile: '/',
}
</script>
<Dropdown custom class="me-2">
<div slot="toggler">
<div class="d-flex align-items-center">
<i class="d-none d-md-inline bi-three-dots-vertical"></i>
</div>
</div>
<DropdownItem header>Actions</DropdownItem>
<DropdownItem href='/test'>Action</DropdownItem>
<DropdownItem divider />
<DropdownItem href="/logout">Logout</DropdownItem>
</Dropdown>
</script>
Configuration
- custom:
Boolean
- Custom toggler. Places a instead of using the default toggler - split:
Boolean
- Make a split dropdown with two buttons - title:
String
- Button Title if using default toggler - dark:
Boolean
- Dropdown dark style - direction:
String
- Direction in which the dropdown will be displayed relatively to its trigger button. Possible values:up | right | left | down (default)
- class - DOM classes
- style - inline style
Percentage
Shows the value property as a percentage and adds increase/decrease icon, configurable font size
Example
<script>
import { Percentage } from '@bizmate-oss/sveltekit-components';
let value = 4.5
</script>
<Percentage {value} fontSize="3rem">
Configuration
- value:
Number
- Current percentage value - fontSize:
String
- Text font-size. The space occupied by the component and the icon's dimensions will be calculated accordingly. Supported size units:px | pt | em | rem