v1.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace zin;
  3. class idLabel extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array
  9. (
  10. 'id?: int|string'
  11. );
  12. public function onAddChild($child)
  13. {
  14. if((is_string($child) || is_int($child)) && !$this->props->has('id'))
  15. {
  16. $this->props->set('id', $child);
  17. return false;
  18. }
  19. }
  20. protected function build()
  21. {
  22. $id = $this->prop('id');
  23. return span
  24. (
  25. setClass('label label-id gray-300-outline size-sm rounded-full flex-none ml-1'),
  26. set($this->getRestProps()),
  27. $id,
  28. $this->children()
  29. );
  30. }
  31. /**
  32. * @param string|int|mixed[] $idOrProps
  33. * @param mixed ...$children
  34. * @return $this
  35. * @param mixed[]|null $props
  36. */
  37. public static function create($idOrProps, $props = null, ...$children)
  38. {
  39. $props = $props ? $props : array();
  40. if(is_array($idOrProps))
  41. {
  42. $props = array_merge($idOrProps, $props);
  43. }
  44. else
  45. {
  46. $props['id'] = $idOrProps;
  47. }
  48. return new static(set($props), ...$children);
  49. }
  50. }