You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

424 lines
13 KiB

  1. ---
  2. layout : 'default'
  3. css : 'checkbox'
  4. element : 'checkbox'
  5. elementType : 'module'
  6. title : 'Checkbox'
  7. description : "A checkbox allows a user to select a value from a small set of options, often binary"
  8. type : 'UI Module'
  9. themes : ['Default']
  10. ---
  11. <script src="/javascript/checkbox.js"></script>
  12. <link rel="stylesheet/less" type="text/css" href="/build/less/definitions/modules/checkbox.less" />
  13. <%- @partial('header', { tabs: 'module' }) %>
  14. <div class="main container">
  15. <div class="ui tab" data-tab="definition">
  16. <h2 class="ui dividing header">Types</h2>
  17. <div class="example">
  18. <h4 class="ui header">Checkbox</h4>
  19. <p>A standard checkbox</p>
  20. <div class="ui checkbox">
  21. <input type="checkbox" name="fun" />
  22. <label>I enjoy having fun</label>
  23. </div>
  24. </div>
  25. <div class="example">
  26. <h4 class="ui header">Slider</h4>
  27. <p>A checkbox can be formatted to emphasize the current selection state</p>
  28. <div class="ui slider checkbox">
  29. <input type="checkbox" name="newsletter" />
  30. <label>Receive weekly poodle newsletter</label>
  31. </div>
  32. </div>
  33. <div class="example">
  34. <h4 class="ui header">Toggle</h4>
  35. <p>A checkbox can be formatted to show an on or off choice</p>
  36. <div class="ui toggle checkbox">
  37. <input type="checkbox" name="public" />
  38. <label>Make my dog's profile public</label>
  39. </div>
  40. </div>
  41. <div class="example">
  42. <h4 class="ui header">Radio Box</h4>
  43. <p>A checkbox can be formatted as a radio element. This means it is an exclusive option.</p>
  44. <div class="ui form">
  45. <div class="grouped inline fields">
  46. <div class="field">
  47. <div class="ui radio checkbox">
  48. <input type="radio" name="fruit" checked="checked" />
  49. <label>Apples</label>
  50. </div>
  51. </div>
  52. <div class="field">
  53. <div class="ui radio checkbox">
  54. <input type="radio" name="fruit" />
  55. <label>Oranges</label>
  56. </div>
  57. </div>
  58. <div class="field">
  59. <div class="ui radio checkbox">
  60. <input type="radio" name="fruit" />
  61. <label>Pears</label>
  62. </div>
  63. </div>
  64. <div class="field">
  65. <div class="ui radio checkbox">
  66. <input type="radio" name="fruit" />
  67. <label>Grapefruit</label>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. <h2 class="ui dividing header">States</h2>
  74. <div class="example">
  75. <h4 class="ui header">Read-only</h4>
  76. <p>A checkbox can be read-only and unable to change states</p>
  77. <div class="ui read-only checkbox">
  78. <input type="checkbox" />
  79. <label>Read Only</label>
  80. </div>
  81. </div>
  82. <div class="example">
  83. <h4 class="ui header">Disabled</h4>
  84. <p>A checkbox can be read-only and unable to change states</p>
  85. <div class="ui info message">
  86. A checkbox can be disabled by either setting the disabled attribute on the hidden input, or class <code>disabled</code> on the <code>ui checkbox</code>
  87. </div>
  88. <div class="ui disabled checkbox">
  89. <input type="checkbox" disabled="disabled" />
  90. <label>Disabled</label>
  91. </div>
  92. <br>
  93. <br>
  94. <div class="ui toggle checkbox">
  95. <input type="checkbox" disabled="disabled" />
  96. <label>Disabled</label>
  97. </div>
  98. </div>
  99. </div>
  100. <div class="ui tab" data-tab="examples">
  101. <h2>Examples</h2>
  102. <div class="example">
  103. <h4 class="ui header">Uncheckable Checkboxes</h4>
  104. <p class="ignored">To make a user able to check a box, but unable to uncheck it, use the <code>uncheckable</code> setting.</p>
  105. <p class="ignored">To always disable a checkbox, add the property <code>disabled</code> to your input.</p>
  106. <p class="ignored">To make a checkbox read-only do not initialize it, or include the <code>read-only</code> class which will not allow toggle events.</p>
  107. <div class="evaluated code" data-type="javascript">
  108. $('#demo3')
  109. .checkbox({
  110. uncheckable: false
  111. })
  112. ;
  113. </div>
  114. <div class="ui form">
  115. <div class="field">
  116. <div class="ui checkbox" id="demo1">
  117. <input type="checkbox" disabled="disabled" checked="checked" />
  118. <label> Disabled</label>
  119. </div>
  120. </div>
  121. <div class="field">
  122. <div class="ui read-only checkbox" id="demo2">
  123. <input type="checkbox" checked="checked" />
  124. <label> Read Only</label>
  125. </div>
  126. </div>
  127. <div class="field">
  128. <div class="ui checkbox" id="demo3">
  129. <input type="checkbox" />
  130. <label> Cannot Be Unchecked</label>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. <div class="example">
  136. <h4 class="ui header">Attaching Events to other Elements</h4>
  137. <p>Checkbox can use the <code>attach events</code> behavior to attach events easily to other activating elements. This defaults to toggling, but other behaviors can be used as well.</p>
  138. <div class="evaluated code">
  139. $('.test.checkbox').checkbox('attach events', '.toggle.button');
  140. $('.test.checkbox').checkbox('attach events', '.check.button', 'check');
  141. $('.test.checkbox').checkbox('attach events', '.uncheck.button', 'uncheck');
  142. </div>
  143. <div class="ui toggle button">Toggle</div>
  144. <div class="ui positive check button">Check</div>
  145. <div class="ui negative uncheck button">Uncheck</div>
  146. <div class="ui six column center aligned stackable divided grid segment">
  147. <div class="column">
  148. <div class="ui test slider checkbox">
  149. <input type="checkbox" />
  150. <label>1</label>
  151. </div>
  152. </div>
  153. <div class="column">
  154. <div class="ui test toggle checkbox">
  155. <input type="checkbox" checked="checked" />
  156. <label>2</label>
  157. </div>
  158. </div>
  159. <div class="column">
  160. <div class="ui test checkbox">
  161. <input type="checkbox" />
  162. <label>3</label>
  163. </div>
  164. </div>
  165. <div class="column">
  166. <div class="ui test slider checkbox">
  167. <input type="checkbox" checked="checked" />
  168. <label>4</label>
  169. </div>
  170. </div>
  171. <div class="column">
  172. <div class="ui test toggle checkbox">
  173. <input type="checkbox" />
  174. <label>5</label>
  175. </div>
  176. </div>
  177. <div class="column">
  178. <div class="ui test checkbox">
  179. <input type="checkbox" />
  180. <label>6</label>
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. </div>
  186. <div class="ui tab" data-tab="usage">
  187. <h2 class="ui dividing header">Initializing</h2>
  188. <div class="no example">
  189. <h4 class="ui dividing header">Checkbox</h4>
  190. <p>A checkbox can be initialized with javascript for increase programmatic control</p>
  191. <div class="code">
  192. $('.ui.checkbox')
  193. .checkbox()
  194. ;
  195. </div>
  196. <div class="code" data-type="html">
  197. <div class="ui checkbox">
  198. <input type="checkbox">
  199. <label>Poodle</label>
  200. </div>
  201. </div>
  202. </div>
  203. <div class="no example">
  204. <h4 class="ui dividing header">Basic Checkbox</h4>
  205. <p>A checkbox can also be used without using javascript by matching the <code>id</code> attribute of the input field to the <code>for</code> attribute of the accompanying label</p>
  206. <div class="code" data-type="html">
  207. <div class="ui checkbox">
  208. <input type="checkbox" id="unique-id" />
  209. <label for="unique-id">Poodle</label>
  210. </div>
  211. </div>
  212. </div>
  213. <h2 class="ui dividing header">Behavior</h2
  214. >
  215. <p>Behaviors are accessible with javascript using the syntax:<p>
  216. <div class="code">
  217. $('.ui.checkbox').checkbox('behavior', argumentOne, argumentTwo...);
  218. </div>
  219. <table class="ui definition celled table segment">
  220. <tr>
  221. <td>toggle</td>
  222. <td>Switches a checkbox from current state</td>
  223. </tr>
  224. <tr>
  225. <td>check</td>
  226. <td>Set a checkbox state to checked</td>
  227. </tr>
  228. <tr>
  229. <td>uncheck</td>
  230. <td>Set a checkbox state to unchecked</td>
  231. </tr>
  232. <tr>
  233. <td>attach events(selector, behavior)</td>
  234. <td>Attach checkbox events to another element</td>
  235. </tr>
  236. <tr>
  237. <td>enable</td>
  238. <td>Enable interaction with a checkbox</td>
  239. </tr>
  240. <tr>
  241. <td>disable</td>
  242. <td>Disable interaction with a checkbox</td>
  243. </tr>
  244. <tr>
  245. <td>is radio</td>
  246. <td>Returns whether element is radio selection</td>
  247. </tr>
  248. <tr>
  249. <td>is checked</td>
  250. <td>Returns whether element is currently checked</td>
  251. </tr>
  252. <tr>
  253. <td>is unchecked</td>
  254. <td>Returns whether element is not checked</td>
  255. </tr>
  256. <tr>
  257. <td>can check</td>
  258. <td>Returns whether element is able to be checked</td>
  259. </tr>
  260. </table>
  261. </div>
  262. <div class="ui tab" data-tab="settings">
  263. <h2 class="ui dividing header">Checkbox</h2>
  264. <p>These settings are specific to checkbox, and determine the parameters of its behavior</p>
  265. <table class="ui celled sortable definition table segment">
  266. <thead>
  267. <th class="three wide"></th>
  268. <th class="three wide">Default</th>
  269. <th>Description</th>
  270. </thead>
  271. <tbody>
  272. <tr>
  273. <td>uncheckable</td>
  274. <td>auto</td>
  275. <td>Setting to true/false will determine whether an input will allow no selection. Auto will set disallow this behavior only for radio boxes</td>
  276. </tr>
  277. <tr>
  278. <td>fireOnInit</td>
  279. <td>true</td>
  280. <td>Whether callbacks for checked status should be fired on init as well as change</td>
  281. </tr>
  282. </tbody>
  283. </table>
  284. <table class="ui celled sortable definition table segment">
  285. <thead>
  286. <th class="three wide"></th>
  287. <th class="three wide">Context</th>
  288. <th>Description</th>
  289. </thead>
  290. <tbody>
  291. <tr>
  292. <td>onChange</td>
  293. <td>HTML input element</td>
  294. <td>Callback after a checkbox is either disabled or enabled.</td>
  295. </tr>
  296. <tr>
  297. <td>onChecked</td>
  298. <td>HTML input element</td>
  299. <td>Callback after a checkbox is checked.</td>
  300. </tr>
  301. <tr>
  302. <td>onUnchecked</td>
  303. <td>HTML input element</td>
  304. <td>Callback after a checkbox is unchecked.</td>
  305. </tr>
  306. <tr>
  307. <td>onEnable</td>
  308. <td>HTML input element</td>
  309. <td>Callback after a checkbox is enabled.</td>
  310. </tr>
  311. <tr>
  312. <td>onDisable</td>
  313. <td>HTML input element</td>
  314. <td>Callback after a checkbox is disabled.</td>
  315. </tr>
  316. </tbody>
  317. </table>
  318. <h2 class="ui dividing header">Module</h2>
  319. <p>These settings are native to all modules, and define how the component ties content to DOM attributes, and debugging settings for the module.</p>
  320. <table class="ui sortable celled definition table">
  321. <thead>
  322. <th></th>
  323. <th class="six wide">Default</th>
  324. <th>Description</th>
  325. </thead>
  326. <tbody>
  327. <tr>
  328. <td>name</td>
  329. <td>Checkbox</td>
  330. <td>Name used in log statements</td>
  331. </tr>
  332. <tr>
  333. <td>namespace</td>
  334. <td>checkbox</td>
  335. <td>Event namespace. Makes sure module teardown does not effect other events attached to an element.</td>
  336. </tr>
  337. <tr>
  338. <td>selector</td>
  339. <td>
  340. <div class="code" data-type="css">
  341. selector : {
  342. input : 'input[type=checkbox], input[type=radio]',
  343. label : 'label'
  344. }
  345. </div>
  346. </td>
  347. <td>Selectors used to find parts of a module</td>
  348. </tr>
  349. <tr>
  350. <td>className</td>
  351. <td>
  352. <div class="code">
  353. className : {
  354. checked : 'checked',
  355. disabled : 'disabled',
  356. radio : 'radio',
  357. readOnly : 'read-only'
  358. }
  359. </div>
  360. </td>
  361. <td>Class names used to determine element state</td>
  362. </tr>
  363. <tr>
  364. <td>debug</td>
  365. <td>false</td>
  366. <td>Debug output to console</td>
  367. </tr>
  368. <tr>
  369. <td>performance</td>
  370. <td>false</td>
  371. <td>Show <code>console.table</code> output with performance metrics</td>
  372. </tr>
  373. <tr>
  374. <td>verbose</td>
  375. <td>false</td>
  376. <td>Debug output includes all internal behaviors</td>
  377. </tr>
  378. <tr>
  379. <td>errors</td>
  380. <td colspan="2">
  381. <div class="code">
  382. error : {
  383. method : 'The method you called is not defined.'
  384. }
  385. </div>
  386. </td>
  387. </tr>
  388. </tbody>
  389. </table>
  390. </div>
  391. </div>