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.

450 lines
14 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>Make my profile visible</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>Accept terms and conditions</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>Subscribe to weekly newsletter</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>Once a week</label>
  50. </div>
  51. </div>
  52. <div class="field">
  53. <div class="ui radio checkbox">
  54. <input type="radio" name="fruit" />
  55. <label>2-3 times a week</label>
  56. </div>
  57. </div>
  58. <div class="field">
  59. <div class="ui radio checkbox">
  60. <input type="radio" name="fruit" />
  61. <label>Once a day</label>
  62. </div>
  63. </div>
  64. <div class="field">
  65. <div class="ui radio checkbox">
  66. <input type="radio" name="fruit" />
  67. <label>Twice a day</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. <h2 class="ui dividing header">Variations</h2>
  100. <div class="example">
  101. <h4 class="ui header">Fitted</h4>
  102. <p>A fitted checkbox does not leave padding for a label</p>
  103. <div class="ui left floated segment">
  104. <div class="ui fitted checkbox">
  105. <input type="checkbox"/>
  106. <label></label>
  107. </div>
  108. </div>
  109. <div class="ui left floated segment">
  110. <div class="ui fitted slider checkbox">
  111. <input type="checkbox"/>
  112. <label></label>
  113. </div>
  114. </div>
  115. <div class="ui left floated segment">
  116. <div class="ui fitted toggle checkbox">
  117. <input type="checkbox"/>
  118. <label></label>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <div class="ui tab" data-tab="examples">
  124. <h2>Examples</h2>
  125. <div class="example">
  126. <h4 class="ui header">Uncheckable Checkboxes</h4>
  127. <p class="ignored">To make a user able to check a box, but unable to uncheck it, use the <code>uncheckable</code> setting.</p>
  128. <p class="ignored">To always disable a checkbox, add the property <code>disabled</code> to your input.</p>
  129. <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>
  130. <div class="evaluated code" data-type="javascript">
  131. $('#demo3')
  132. .checkbox({
  133. uncheckable: false
  134. })
  135. ;
  136. </div>
  137. <div class="ui form">
  138. <div class="field">
  139. <div class="ui checkbox" id="demo1">
  140. <input type="checkbox" disabled="disabled" checked="checked" />
  141. <label> Disabled</label>
  142. </div>
  143. </div>
  144. <div class="field">
  145. <div class="ui read-only checkbox" id="demo2">
  146. <input type="checkbox" checked="checked" />
  147. <label> Read Only</label>
  148. </div>
  149. </div>
  150. <div class="field">
  151. <div class="ui checkbox" id="demo3">
  152. <input type="checkbox" />
  153. <label> Cannot Be Unchecked</label>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <div class="example">
  159. <h4 class="ui header">Attaching Events to other Elements</h4>
  160. <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>
  161. <div class="evaluated code">
  162. $('.test.checkbox').checkbox('attach events', '.toggle.button');
  163. $('.test.checkbox').checkbox('attach events', '.check.button', 'check');
  164. $('.test.checkbox').checkbox('attach events', '.uncheck.button', 'uncheck');
  165. </div>
  166. <div class="ui toggle button">Toggle</div>
  167. <div class="ui positive check button">Check</div>
  168. <div class="ui negative uncheck button">Uncheck</div>
  169. <div class="ui six column center aligned stackable divided grid segment">
  170. <div class="column">
  171. <div class="ui test slider checkbox">
  172. <input type="checkbox" />
  173. <label>1</label>
  174. </div>
  175. </div>
  176. <div class="column">
  177. <div class="ui test toggle checkbox">
  178. <input type="checkbox" checked="checked" />
  179. <label>2</label>
  180. </div>
  181. </div>
  182. <div class="column">
  183. <div class="ui test checkbox">
  184. <input type="checkbox" />
  185. <label>3</label>
  186. </div>
  187. </div>
  188. <div class="column">
  189. <div class="ui test slider checkbox">
  190. <input type="checkbox" checked="checked" />
  191. <label>4</label>
  192. </div>
  193. </div>
  194. <div class="column">
  195. <div class="ui test toggle checkbox">
  196. <input type="checkbox" />
  197. <label>5</label>
  198. </div>
  199. </div>
  200. <div class="column">
  201. <div class="ui test checkbox">
  202. <input type="checkbox" />
  203. <label>6</label>
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. </div>
  209. <div class="ui tab" data-tab="usage">
  210. <h2 class="ui dividing header">Initializing</h2>
  211. <div class="no example">
  212. <h4 class="ui dividing header">Checkbox</h4>
  213. <p>A checkbox can be initialized with javascript for increase programmatic control</p>
  214. <div class="code">
  215. $('.ui.checkbox')
  216. .checkbox()
  217. ;
  218. </div>
  219. <div class="code" data-type="html">
  220. <div class="ui checkbox">
  221. <input type="checkbox">
  222. <label>Poodle</label>
  223. </div>
  224. </div>
  225. </div>
  226. <div class="no example">
  227. <h4 class="ui dividing header">Basic Checkbox</h4>
  228. <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>
  229. <div class="code" data-type="html">
  230. <div class="ui checkbox">
  231. <input type="checkbox" id="unique-id" />
  232. <label for="unique-id">Poodle</label>
  233. </div>
  234. </div>
  235. </div>
  236. <h2 class="ui dividing header">Behavior</h2
  237. >
  238. <p>Behaviors are accessible with javascript using the syntax:<p>
  239. <div class="code">
  240. $('.ui.checkbox').checkbox('behavior', argumentOne, argumentTwo...);
  241. </div>
  242. <table class="ui definition celled table segment">
  243. <tr>
  244. <td>toggle</td>
  245. <td>Switches a checkbox from current state</td>
  246. </tr>
  247. <tr>
  248. <td>check</td>
  249. <td>Set a checkbox state to checked</td>
  250. </tr>
  251. <tr>
  252. <td>uncheck</td>
  253. <td>Set a checkbox state to unchecked</td>
  254. </tr>
  255. <tr>
  256. <td>attach events(selector, behavior)</td>
  257. <td>Attach checkbox events to another element</td>
  258. </tr>
  259. <tr>
  260. <td>enable</td>
  261. <td>Enable interaction with a checkbox</td>
  262. </tr>
  263. <tr>
  264. <td>disable</td>
  265. <td>Disable interaction with a checkbox</td>
  266. </tr>
  267. <tr>
  268. <td>is radio</td>
  269. <td>Returns whether element is radio selection</td>
  270. </tr>
  271. <tr>
  272. <td>is checked</td>
  273. <td>Returns whether element is currently checked</td>
  274. </tr>
  275. <tr>
  276. <td>is unchecked</td>
  277. <td>Returns whether element is not checked</td>
  278. </tr>
  279. <tr>
  280. <td>can check</td>
  281. <td>Returns whether element is able to be checked</td>
  282. </tr>
  283. </table>
  284. </div>
  285. <div class="ui tab" data-tab="settings">
  286. <h2 class="ui dividing header">Checkbox</h2>
  287. <p>These settings are specific to checkbox, and determine the parameters of its behavior</p>
  288. <table class="ui celled sortable definition table segment">
  289. <thead>
  290. <th class="three wide"></th>
  291. <th class="three wide">Default</th>
  292. <th>Description</th>
  293. </thead>
  294. <tbody>
  295. <tr>
  296. <td>uncheckable</td>
  297. <td>auto</td>
  298. <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>
  299. </tr>
  300. <tr>
  301. <td>fireOnInit</td>
  302. <td>true</td>
  303. <td>Whether callbacks for checked status should be fired on init as well as change</td>
  304. </tr>
  305. </tbody>
  306. </table>
  307. <table class="ui celled sortable definition table segment">
  308. <thead>
  309. <th class="three wide"></th>
  310. <th class="three wide">Context</th>
  311. <th>Description</th>
  312. </thead>
  313. <tbody>
  314. <tr>
  315. <td>onChange</td>
  316. <td>HTML input element</td>
  317. <td>Callback after a checkbox is either disabled or enabled.</td>
  318. </tr>
  319. <tr>
  320. <td>onChecked</td>
  321. <td>HTML input element</td>
  322. <td>Callback after a checkbox is checked.</td>
  323. </tr>
  324. <tr>
  325. <td>onUnchecked</td>
  326. <td>HTML input element</td>
  327. <td>Callback after a checkbox is unchecked.</td>
  328. </tr>
  329. <tr>
  330. <td>onEnable</td>
  331. <td>HTML input element</td>
  332. <td>Callback after a checkbox is enabled.</td>
  333. </tr>
  334. <tr>
  335. <td>onDisable</td>
  336. <td>HTML input element</td>
  337. <td>Callback after a checkbox is disabled.</td>
  338. </tr>
  339. </tbody>
  340. </table>
  341. <h2 class="ui dividing header">Module</h2>
  342. <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>
  343. <table class="ui sortable celled definition table">
  344. <thead>
  345. <th></th>
  346. <th class="six wide">Default</th>
  347. <th>Description</th>
  348. </thead>
  349. <tbody>
  350. <tr>
  351. <td>name</td>
  352. <td>Checkbox</td>
  353. <td>Name used in log statements</td>
  354. </tr>
  355. <tr>
  356. <td>namespace</td>
  357. <td>checkbox</td>
  358. <td>Event namespace. Makes sure module teardown does not effect other events attached to an element.</td>
  359. </tr>
  360. <tr>
  361. <td>selector</td>
  362. <td>
  363. <div class="code" data-type="css">
  364. selector : {
  365. input : 'input[type=checkbox], input[type=radio]',
  366. label : 'label'
  367. }
  368. </div>
  369. </td>
  370. <td>Selectors used to find parts of a module</td>
  371. </tr>
  372. <tr>
  373. <td>className</td>
  374. <td>
  375. <div class="code">
  376. className : {
  377. checked : 'checked',
  378. disabled : 'disabled',
  379. radio : 'radio',
  380. readOnly : 'read-only'
  381. }
  382. </div>
  383. </td>
  384. <td>Class names used to determine element state</td>
  385. </tr>
  386. <tr>
  387. <td>debug</td>
  388. <td>false</td>
  389. <td>Debug output to console</td>
  390. </tr>
  391. <tr>
  392. <td>performance</td>
  393. <td>false</td>
  394. <td>Show <code>console.table</code> output with performance metrics</td>
  395. </tr>
  396. <tr>
  397. <td>verbose</td>
  398. <td>false</td>
  399. <td>Debug output includes all internal behaviors</td>
  400. </tr>
  401. <tr>
  402. <td>errors</td>
  403. <td colspan="2">
  404. <div class="code">
  405. error : {
  406. method : 'The method you called is not defined.'
  407. }
  408. </div>
  409. </td>
  410. </tr>
  411. </tbody>
  412. </table>
  413. </div>
  414. </div>