Checkbox - 图1

Checkbox Svelte Component

Checkbox Svelte component represents Checkbox component.

Checkbox Components

There are following components included:

  • Checkbox

Checkbox Properties

PropTypeDefaultDescription
<Checkbox> properties
checkedbooleanDefines whether the checkbox input is checked or not
indeterminatebooleanDefines whether the checkbox input is in indeterminate state or not
namestring
number
Checkbox input name
valuestring
number
boolean
Checkbox input value
disabledbooleanDefines whether the checkbox input is disabled
readonlybooleanDefines whether the checkbox input is readonly

Checkbox Events

EventDescription
<Checkbox> events
changeEvent will be triggered when checkbox state changed

Checkboxes List

Checkboxes List is not a separate component, but just a particular case of using <List>, <ListItem>.

  1. <List>
  2. <!-- Additional "checkbox" prop to enable checkbox list item -->
  3. <ListItem checkbox value="check_1" checked title="Checkbox 1" />
  4. <ListItem checkbox value="check_2" title="Checkbox 2" />
  5. </List>

Examples

  1. <Page>
  2. <Navbar title="Checkbox" />
  3. <BlockTitle>Inline</BlockTitle>
  4. <Block strong>
  5. <p>Lorem <Checkbox name="checkbox-1"></Checkbox> ipsum dolor sit amet, consectetur adipisicing elit. Alias beatae illo nihil aut eius commodi sint eveniet aliquid eligendi <Checkbox name="checkbox-2" checked></Checkbox> ad delectus impedit tempore nemo, enim vel praesentium consequatur nulla mollitia!</p>
  6. </Block>
  7. <BlockTitle>Checkbox Group</BlockTitle>
  8. <List>
  9. <ListItem checkbox title="Books" name="demo-checkbox" checked></ListItem>
  10. <ListItem checkbox title="Movies" name="demo-checkbox"></ListItem>
  11. <ListItem checkbox title="Food" name="demo-checkbox"></ListItem>
  12. <ListItem checkbox title="Drinks" name="demo-checkbox"></ListItem>
  13. </List>
  14. <BlockTitle>Indeterminate State</BlockTitle>
  15. <List>
  16. <ListItem
  17. checkbox
  18. title="Movies"
  19. name="demo-checkbox"
  20. checked={movies.length === 2}
  21. indeterminate={movies.length === 1}
  22. onChange={onMoviesChange}
  23. >
  24. <ul slot="root">
  25. <ListItem
  26. checkbox
  27. title="Movie 1"
  28. name="demo-checkbox"
  29. value="Movie 1"
  30. checked={movies.indexOf('Movie 1') >= 0}
  31. onChange={onMovieChange}
  32. />
  33. <ListItem
  34. checkbox
  35. title="Movie 2"
  36. name="demo-checkbox"
  37. value="Movie 2"
  38. checked={movies.indexOf('Movie 2') >= 0}
  39. onChange={onMovieChange}
  40. />
  41. </ul>
  42. </ListItem>
  43. </List>
  44. <BlockTitle>With Media Lists</BlockTitle>
  45. <List mediaList>
  46. <ListItem
  47. checkbox
  48. checked
  49. name="demo-media-checkbox"
  50. title="Facebook"
  51. after="17:14"
  52. subtitle="New messages from John Doe"
  53. text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
  54. />
  55. <ListItem
  56. checkbox
  57. name="demo-media-checkbox"
  58. title="John Doe (via Twitter)"
  59. after="17:11"
  60. subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
  61. text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
  62. />
  63. <ListItem
  64. checkbox
  65. name="demo-media-checkbox"
  66. title="Facebook"
  67. after="16:48"
  68. subtitle="New messages from John Doe"
  69. text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
  70. />
  71. <ListItem
  72. checkbox
  73. name="demo-media-checkbox"
  74. title="John Doe (via Twitter)"
  75. after="15:32"
  76. subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
  77. text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
  78. />
  79. </List>
  80. </Page>
  81. <script>
  82. import {Page, Navbar, BlockTitle, Block, Checkbox, List, ListItem} from 'framework7-svelte';
  83. let movies = ['Movie 1'];
  84. function onMovieChange(e) {
  85. var value = e.target.value;
  86. if (e.target.checked) {
  87. movies.push(value);
  88. } else {
  89. movies.splice(movies.indexOf(value), 1);
  90. }
  91. movies = movies;
  92. }
  93. function onMoviesChange() {
  94. if (movies.length === 1 || movies.length === 0) {
  95. movies = ['Movie 1', 'Movie 2'];
  96. } else if (movies.length === 2) {
  97. movies = [];
  98. }
  99. }
  100. </script>

← Cards

Chips / Tags →