InputFactoryTrait.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * PHP表单生成器
  4. *
  5. * @package FormBuilder
  6. * @author xaboy <xaboy2005@qq.com>
  7. * @version 2.0
  8. * @license MIT
  9. * @link https://github.com/xaboy/form-builder
  10. * @document http://php.form-create.com
  11. */
  12. namespace FormBuilder\UI\Elm\Traits;
  13. use FormBuilder\UI\Elm\Components\Input;
  14. trait InputFactoryTrait
  15. {
  16. /**
  17. * input输入框组件
  18. *
  19. * @param string $field
  20. * @param string $title
  21. * @param string $value
  22. * @param string $type
  23. * @return Input
  24. */
  25. public static function input($field, $title, $value = '', $type = Input::TYPE_TEXT)
  26. {
  27. $input = new Input($field, $title, (string)$value);
  28. return $input->type($type);
  29. }
  30. /**
  31. * text 类型输入框
  32. *
  33. * @param string $field
  34. * @param string $title
  35. * @param string $value
  36. * @return Input
  37. */
  38. public static function text($field, $title, $value = '')
  39. {
  40. return self::input($field, $title, $value);
  41. }
  42. /**
  43. * password 类型输入框
  44. *
  45. * @param string $field
  46. * @param string $title
  47. * @param string $value
  48. * @return Input
  49. */
  50. public static function password($field, $title, $value = '')
  51. {
  52. return self::input($field, $title, $value, Input::TYPE_PASSWORD);
  53. }
  54. /**
  55. * textarea 类型输入框
  56. *
  57. * @param string $field
  58. * @param string $title
  59. * @param string $value
  60. * @return Input
  61. */
  62. public static function textarea($field, $title, $value = '')
  63. {
  64. return self::input($field, $title, $value, Input::TYPE_TEXTAREA);
  65. }
  66. /**
  67. * url 类型输入框
  68. *
  69. * @param string $field
  70. * @param string $title
  71. * @param string $value
  72. * @return Input
  73. */
  74. public static function url($field, $title, $value = '')
  75. {
  76. return self::input($field, $title, $value, Input::TYPE_URL);
  77. }
  78. /**
  79. * email 类型输入框
  80. *
  81. * @param string $field
  82. * @param string $title
  83. * @param string $value
  84. * @return Input
  85. */
  86. public static function email($field, $title, $value = '')
  87. {
  88. return self::input($field, $title, $value, Input::TYPE_EMAIL);
  89. }
  90. /**
  91. * date 类型输入框
  92. *
  93. * @param string $field
  94. * @param string $title
  95. * @param string $value
  96. * @return Input
  97. */
  98. public static function idate($field, $title, $value = '')
  99. {
  100. return self::input($field, $title, $value, Input::TYPE_DATE);
  101. }
  102. }