SM Components

Getting Started

Components

Total components

Overview

Component-based design is the cornerstone of the modern UI development process. With rise of more UI frameworks every day, the web platform has a serious issue of fragmentation and portability.

Web components to the rescue! This is the collection of web components (WC here forward) that we use at RanchiMall, especially since we are a framework-less development environment so this was a logical choice.

Features

  • Native and Cross framework support
  • Encapsulated style and functionality
  • Easy styling
  • Adaptive scaling

Quick Start

  1. To start using these components, Select the ones you want to add to your project. You can un-check 'get minified' to get the readable code.
  2. Now you can download or copy the source code for selected components. You might get a warning while downloading like this file is not safe, please allow the download as this is caused when downloading files with '.js' extension. These components are 100% safe to use.
  3. Link the downloaded js before </body>
Get minified Select all Clear all
Copy source code Download JS file

Global styling

These components use CSS variables to customize styling. they share some CSS variables that make global styling easier.
Of course you can set these variables at individual component CSS rule set level.

Some common CSS variables and their use

Variable

Use

--accent-color

Color which will be used for denoting active state

--text-color

default text color for all components.
( Use comma separated rgb values. e.g 17, 17, 17 )

--background-color

default background color for all components.
( Use comma separated rgb values. e.g 255, 255, 255 )

--danger-color

Used for error/invalid state

Buttons

Default button

Variants

These are styled variations of base component

Variant type

Example

primary

Primary

outlined

Outlined

no--outline

No outline

How to define variant

Primary Outlined No outline

States

Disabled

To disable the button add disabled attribute.

Disabled Disabled

Attributes

All the native HTML checkbox attributes are valid

Attribute

Description

disabled (boolean)

Button is disabled by default. all the interactions are disabled

type (string)

Has values submit reset
Can only used withing sm-form to submit or reset the form.

Styling

CSS variables used to style this component

Variable

Description

--background

Define background of button. accepts all values of CSS background property

--border-radius

Set curvature at button corners

--padding

Specify padding of button

Checkbox

sm-checkbox supports all the attributes of native HTML5 checkbox

linking some HTML element with sm-checbox using label tag won't work.
Add the element inside the opening and closing checkbox tag.

Interactive demo

Check this box

States

Checked

To make checkbox checked by default add checked attribute.

Checked checkbox
Checked checkbox

Disabled

To disable the checkbox add disabled attribute.

Disabled checkbox
Disabled checkbox

Attributes

All the native HTML checkbox attributes are valid

Attribute

Description

checked (boolean)

If present, checkbox is set to checked state as default.

disabled (boolean)

If present checkbox is set to disabled state. all the interactions are disabled

value (string)

Sets value of checkbox which can be accessed by value property with JS

Styling

CSS variables used to style this component

Variable

Description

--border-color

Defines color of un-checked checkbox border

--border-radius

Defines border-radius of checkbox square

--height

Defines height of checkbox

--width

Defines width of checkbox

Copy

Interactive demo

this will be copied
this will be copied

Usage

Attributes

Attribute

Description

value ( string )

Defines content that will be copied when copy button is clicked

Styling

CSS variables used to style this component

Variable

Description

--button-background-color

Defines background color of copy button

--button-border-radius

Defines border-radius of copy button

Supported events

Event

Description

copy

Fired when text is copied by user.

File input

<file-input> is essentially native <input type="file"/> with added style.
So every attribute supported by native file input is supported as can be used in exactly same way.

Interactive demo

Select multiple files Select multiple files

Attributes

Attribute

Description

accept

One or more unique file type specifiers describing file types to allow

capture

What source to use for capturing image or video data

files

A FileList listing the chosen files

multiple

A Boolean which, if present, indicates that the user may choose more than one file

Form

Browser support for web components form validation or form submition is not perfect. so to circumvent this problem <sm-form> can be used.

Interactive demo

Login

Supported functions

Function

Description

reset()

When this function is called upon form element. all the form elements (sm- form components only) will be reset to default state.

Nested element behaviour

Element

behaviour

sm-button variant="primary" or type="submit"

Whenever enter is pressed inside an active sm-input, this will fire click event.
This will also change state depending opon validation conditions.

sm-button type="reset"

When clicked, the whole form will reset.

Hamburger menu

Hamburger menu closed

Hamburger menu closed

Hamburger menu opened

Hamburger menu open

Usage

Input

Interactive demo

Variants

outlined is only one styled variation. Default is filled which doesn't require variant specified.

Custom Attributes

All the native HTML input attributes are valid. These are additional attributes which can be used to add more functionality

Attribute

Description

animate (boolean)

If present, placeholder of input will be animated to occupy space above enterned text instead of vanishing.

error-text (string)

Message specified as value of this attribute will be shown if validation fails.

Styling

CSS variables used to style this component

Variable

Description

--background

Defines background property of input. Any valid CSS background values are supported.

--border-radius

Sets border-radius of input.

--icon-gap

Sets space between input icon and input box. Default is "0.5rem"

--font-size

Sets font size of input text. Default is "1rem".

--padding

Sets padding around whole input box including icon.

--width

Sets width of input box.

Supported functions

Function

Description

focusIn()

To give focus to this component use this function instead of focus()

reset()

When this function is called value will be set to empty string.

Custom Setters

Function

Description

customValidation

If you want to perform custom validation on input value, set the desired validation function.

disabled

Set disabled state to true or false

value

Sets the value of input with JS

Notifications

To start using notifications add the <sm-notifications> at top level of markup like just below starting <body> tag.

Supported functions

Function

Description

push()

Used to display notifications with two parameters.
Notification text and notification options.

clearAll()

Removes all the notifications present in notification drawer.

Push() options

Property

Description

icon (svg)

To display custom icon with notification icon option can be used.

pinned (Boolean)

If set true notifications won't disappear after some time. they need to be dismissed by user manually.

Interactive demo

push pinned notification

Radio button

Radio buttons are useful whenever only one option needs to be selected from mutiple options. this functionality can be achieved by assigning same name to the group of radio buttons.
sm-radio supports all the attributes of native HTML5 radio.

linking some HTML element with sm-radio using label tag won't work.
Add the element inside the opening and closing sm-radio tag.

Interactive demo

  On
  Off
  ðŸ¤·
  On
  Off
  ðŸ¤·

States

Checked

To make switch turned on by default add checked attribute.

Checked radio button
Checked radio button

Disabled

To disable the radio button add disabled attribute.

Disabled radio button
Disabled radio button

Attributes

All the native HTML radio attributes are valid

Attribute

Description

checked (boolean)

If present, radio button is set to checked state as default.

disabled (boolean)

If present radio button is set to disabled state. all the interactions are disabled

name (string)

Can be used to group radio buttons with same name. only one radio button will be active in a group.

value (string)

Sets value of radio button which can be accessed by value property with JS

Select

<sm-select> is very similar to starndatd HTML5 select and it's markup stucture is also identical.

Interactive demo

option1 option2 option3 option1 option2 option3

Usage

States

Disabled

To disable the select add disabled attribute.

option1 option2 option3

Supported events

These are the events that will be fired when component state changes

Event

Description

change

Whenever a different options is selected by user the this event is fired.
You can listen to this event and access the current value with event object event.target.value

Spinner

Just drop the sm-spinner in markup where you want to show the spinner

Switch

sm-switch supports all the attributes of native HTML5 checkbox

linking some HTML element with sm-switch using label tag won't work.
Add the element inside the opening and closing sm-switch tag.

Interactive demo

Turn the switch

States

Checked

To make switch turned on by default add checked attribute.

On switch
On switch

Disabled

To disable the switch add disabled attribute.

Disabled checkbox
Disabled checkbox

Attributes

All the native HTML checkbox attributes are valid

Attribute

Description

checked (boolean)

If present, switch is set to checked state as default.

disabled (boolean)

If present switch is set to disabled state. all the interactions are disabled

value (string)

Sets value of switch which can be accessed by value property with JS

Chips

This is a modern interpretation of classical HTML select tag. More suitable for touch devices,

Interactive demo

Sort by Relevance Popularity Price Rating Relevance Popularity Price Rating

Custom attributes

Attribute

Description

multiline ( Boolean )

If present, options will wrap around instead of overflowing horizontally.

Styling

CSS variables used to style this component

Variable

Description

--gap

Defines space between options. Default is "0.5rem".

Supported events

These are the events that will be fired when component state changes

Event

Description

change

Whenever a different options is selected by user the this event is fired.
You can listen to this event and access the current value with event object event.target.value

Usage

Tabs

This component can be used sub-page navigation.

Interactive demo

Audio Video

Audio

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Exercitationem esse quod quae repellat qui. Expedita fugiat voluptates beatae itaque corporis!

Video

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Exercitationem esse quod quae repellat qui. Expedita fugiat voluptates beatae itaque corporis!

Usage

Audio Video

Audio

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Exercitationem esse quod quae repellat qui. Expedita fugiat voluptates beatae itaque corporis!

Video

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Exercitationem esse quod quae repellat qui. Expedita fugiat voluptates beatae itaque corporis!

There are three components that together make the tabs components.

  1. sm-tab-header
  2. sm-tab
  3. sm-tab-panels

sm-tab-header

This is the first half of tabs that include the tabs header and actual tab buttons.

Audio Video

Supported attributes

Attribute

Description

variant ( string )

Specifies variant of sm-tab-header. Only value can be tab

target ( string )

Pass in the ID of respective sm-tab-panels to link them. This is how sm-tab-header communicates with sm-tab-panel on which tab or panel should be displayed.

Variants

tab is the only other variant than default style.

Audio Video

Audio

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Exercitationem esse quod quae repellat qui. Expedita fugiat voluptates beatae itaque corporis!

Video

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Exercitationem esse quod quae repellat qui. Expedita fugiat voluptates beatae itaque corporis!

Audio Video

Tags input

This component has a very specific use case and that is for accepting tags. Each time user presses enter or space, a new tag is created. Only unique values are allowed.

Interactive demo

Attributes

Attribute

Description

placeholder ( string )

Define some string to let user know which kind of input is required.

limit ( number )

Set a limit of tags that will be accepted atmost

Styling

CSS variables used to style this component

Variable

Description

--background

Defines background of tags-input. Any valid CSS background property values are supported.

--border-radius

Defines border-radius of tags-input

Supported functions

Function

Description

focusIn()

To give focus to this component use this function instead of focus()

reset()

When this function is called value will be set to empty string.

Usage

Textarea

Textarea is suitable component where multiline input is required. you can either specify the number of lines textarea should expand or let the textarea expand according to user input until a max-height is reached.

Interactive demo

Variants

outlined is only one styled variation. Default is filled which doesn't require variant specified.

Supported Attributes

All the native HTML textarea attributes are valid.

Attribute

Description

disabled (boolean)

If present, all the interactions will be blocked.

rows (number)

Sets the number of rows textarea will be expanded by default. Default is "1".

value (string)

Sets the default value of textarea.

Styling

CSS variables used to style this component

Variable

Description

--background

Defines background textarea. Any valid CSS background property values are supported.

--border-radius

Defines border-radius of textarea

--max-height

Defines max-height to which textarea is allowed to expand. Default is "8rem"

Supported functions

Function

Description

focusIn()

To give focus to this component use this function instead of focus()

reset()

When this function is called value will be set to empty string.

Setters

Function

Description

disabled

Set disabled state to true or false

value

Sets the value of textarea with JS

Usage

Text field

This component can be used in scenarios where you need to display a name or something that user should be able to edit directly in-place instead of going to other UI element.

Interactive demo

Usage

Custom attributes

Attribute

Description

disabled ( Boolean )

If present, text can't be edited.

value ( string )

Set initial text that can be edited by user.

Supported events

Event

Description

change

Fired when text changes are saved by user.

Theme toggle

Use theme-toggle to create light/dark theme easily with CSS variables.

When this is toggled by user the component changes the custom data attribute data-theme="" on HTML body tag to either light or dark

By default theme is set to OS level preferred-color-scheme ( supported by Android, iOS, Windows and MacOS ).

Interactive demo

HTML

CSS

Styling

CSS variables used to style this component

Variable

Description

--height

Defines height of toggle button

--width

Defines width of toggle button

Custom events

These are the events that will be fired when component state changes

Event

Description

themechange

Whenever theme is toggled by user the themechange event is fired.
You can listen to this event and access the current value of toggle with event object event.detail.theme