UI components · Data entry
Switch
States
The 3 reference states silverpoint declares for Switch, live on both grounds, with their code. As in upstream's documentation the examples are uncontrolled: the state's value is the default value. Pick a framework once and every example on the site follows it.
off
import '@silverpoint/fonts/fonts.css';
import '@silverpoint/grounds/styles.css';
import '@silverpoint/grounds/ui.css';
import { SpSwitch } from '@silverpoint/react/ui/switch';
<SpSwitch label="Linked hover" name="linked" /><script setup lang="ts">
import '@silverpoint/fonts/fonts.css';
import '@silverpoint/grounds/styles.css';
import '@silverpoint/grounds/ui.css';
import { SpSwitch } from '@silverpoint/vue/ui/switch';
</script>
<template>
<SpSwitch label="Linked hover" name="linked" :default-value="false" />
</template>// src/styles.css:
// @import '@silverpoint/fonts/fonts.css';
// @import '@silverpoint/grounds/styles.css';
// @import '@silverpoint/grounds/ui.css';
import { Component } from '@angular/core';
import { SpSwitch } from '@silverpoint/angular/ui/switch';
@Component({
selector: 'app-root',
imports: [SpSwitch],
template: `
<sp-switch label="Linked hover" name="linked" [defaultValue]="false" />
`,
})
export class App {}from reflex_silverpoint_react import sp_switch
sp_switch(
label="Linked hover",
name="linked",
default_checked=False,
)on
import '@silverpoint/fonts/fonts.css';
import '@silverpoint/grounds/styles.css';
import '@silverpoint/grounds/ui.css';
import { SpSwitch } from '@silverpoint/react/ui/switch';
<SpSwitch label="Precision" name="precision" defaultChecked /><script setup lang="ts">
import '@silverpoint/fonts/fonts.css';
import '@silverpoint/grounds/styles.css';
import '@silverpoint/grounds/ui.css';
import { SpSwitch } from '@silverpoint/vue/ui/switch';
</script>
<template>
<SpSwitch label="Precision" name="precision" :default-value="true" />
</template>// src/styles.css:
// @import '@silverpoint/fonts/fonts.css';
// @import '@silverpoint/grounds/styles.css';
// @import '@silverpoint/grounds/ui.css';
import { Component } from '@angular/core';
import { SpSwitch } from '@silverpoint/angular/ui/switch';
@Component({
selector: 'app-root',
imports: [SpSwitch],
template: `
<sp-switch label="Precision" name="precision" [defaultValue]="true" />
`,
})
export class App {}from reflex_silverpoint_react import sp_switch
sp_switch(
label="Precision",
name="precision",
default_checked=True,
)disabled
import '@silverpoint/fonts/fonts.css';
import '@silverpoint/grounds/styles.css';
import '@silverpoint/grounds/ui.css';
import { SpSwitch } from '@silverpoint/react/ui/switch';
<SpSwitch label="Precision" name="precision" disabled defaultChecked /><script setup lang="ts">
import '@silverpoint/fonts/fonts.css';
import '@silverpoint/grounds/styles.css';
import '@silverpoint/grounds/ui.css';
import { SpSwitch } from '@silverpoint/vue/ui/switch';
</script>
<template>
<SpSwitch label="Precision" name="precision" disabled :default-value="true" />
</template>// src/styles.css:
// @import '@silverpoint/fonts/fonts.css';
// @import '@silverpoint/grounds/styles.css';
// @import '@silverpoint/grounds/ui.css';
import { Component } from '@angular/core';
import { SpSwitch } from '@silverpoint/angular/ui/switch';
@Component({
selector: 'app-root',
imports: [SpSwitch],
template: `
<sp-switch
label="Precision"
name="precision"
[disabled]="true"
[defaultValue]="true"
/>
`,
})
export class App {}from reflex_silverpoint_react import sp_switch
sp_switch(
label="Precision",
name="precision",
disabled=True,
default_checked=True,
)Import
Each component has its own subpath under ui/, and every adapter exports them all from ui. Import @silverpoint/grounds/ui.css once, beside styles.css; Reflex adds it for you.
| Framework | Import |
|---|---|
| React | import { SpSwitch } from '@silverpoint/react/ui/switch'; |
| Vue | import { SpSwitch } from '@silverpoint/vue/ui/switch'; |
| Angular | import { SpSwitch } from '@silverpoint/angular/ui/switch'; // <sp-switch> |
| Reflex | from reflex_silverpoint_react import sp_switch |
Binding the value
Controlled or uncontrolled, the way each framework does it. The change event carries the new value itself (a string, a bool or a number), never a DOM event.
| Framework | Controlled | Uncontrolled |
|---|---|---|
| React | checked / onChange | defaultChecked |
| Vue | v-model="x" | default-value |
| Angular | [(value)]="x", ngModel, formControl | [defaultValue] |
| Reflex | checked=State.x, on_change=State.set_x | default_checked=… |
Props
The props Switch adds to the ones every UI component takes.
| React / Angular | Vue | Reflex | Type | Description |
|---|---|---|---|---|
label | label | label | str | The visible text and accessible name. Required. |
name | name | name | str | Form field name; submitted as on when on. |
disabled | disabled | disabled | bool | Not focusable and not submitted. |
checked | checked | checked | bool | Controlled state. |
defaultChecked | default-checked | default_checked | bool | Initial state of an uncontrolled switch. |
onChange | on-change | on_change | event | The new state (a bool). |
Common props
Every UI component also takes these. Like a chart's, they fall back to the dashboard the component sits in, then to the provider. Read more about the UI components.
| React / Angular | Vue | Reflex | Type | Description |
|---|---|---|---|---|
id | id | id | str | The frame variant and every related id derive from it. |
ground | ground | ground | Literal['silverpoint', 'cyanotype'] | str | dict[str, Any] | Style ground: "silverpoint" or "cyanotype", or a ground object. Defaults to the dashboard's, then the provider's, or silverpoint. |
substrate | substrate | substrate | Literal['cream', 'green', 'blue', 'ochre', 'prussian'] | Prepared substrate within the ground. |
mode | mode | mode | Literal['ink', 'precision'] | ink by default; precision disables inking. |
seed | seed | seed | str | int | Seed of the frame's hand; overrides id for the frame variant only. |
size | size | size | Literal['sm', 'md', 'lg'] | Control size: sm, md (default) or lg. |
palette | palette | palette | dict[str, str] | Colours over the ground's (set with palette=), merged over the dashboard's and the provider's. |
className | class-name | class_name | str | Added to the component's root element, after its own classes. |