v1.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'checkbox' . DS . 'v1.php';
  4. class checkBtn extends checkbox
  5. {
  6. public static function getPageCSS()
  7. {
  8. return <<<CSS
  9. .check-btn > input + label {color: var(--color-gray-500)}
  10. .check-btn > input:checked + label {background-color: var(--color-primary-50); color:var(--color-primary-500); --tw-ring-color: var(--color-primary-400); z-index: 1}
  11. .check-btn > input:checked + label > svg {opacity: 1; top: -1px; right: -1px}
  12. CSS;
  13. }
  14. protected function buildPrimary()
  15. {
  16. list($id, $text, $name, $checked, $disabled, $type, $typeClass, $rootClass, $labelClass, $labelStyle, $value) = $this->prop(array('id', 'text', 'name', 'checked', 'disabled', 'type', 'typeClass', 'rootClass', 'labelClass', 'labelStyle', 'value'));
  17. if(empty($typeClass)) $typeClass = $type;
  18. if(empty($id)) $id = empty($name) ? $this->gid : ($name . '_' . $value);
  19. return div
  20. (
  21. setClass("$typeClass-btn check-btn", $rootClass, array('disabled' => $disabled)),
  22. h::input
  23. (
  24. set::type($type),
  25. set::id($id),
  26. set::name($name),
  27. set::checked($checked),
  28. setClass('hidden'),
  29. set($this->props->skip('text,primary,typeClass,rootClass,id,labelClass'))
  30. ),
  31. h::label(set('for', $id), setClass($labelClass, 'btn'), setStyle($labelStyle ? $labelStyle : array()), html($text), html('<svg class="opacity-0 absolute top-0 right-0 transition-all" xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="none" xmlns:v="https://vecta.io/nano"><path d="M0 0h16a2 2 0 0 1 2 2v16L9.818 9.818 0 0z" fill="currentColor"/><path d="M11.307 7.2L9 4.96l.631-.613 1.676 1.628L14.369 3l.631.613L11.307 7.2h0z" fill="#fff" stroke="#fff" stroke-width=".16"/></svg>')),
  32. $this->children()
  33. );
  34. }
  35. }