index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div class="cip-divider"
  3. :class="[dividerClass, proxyValue ?? 'empty-divider']"
  4. :style="{ width: width,
  5. height: config.dividerHeight,
  6. color: config.textColor,
  7. 'border-color': config.dividerColor,
  8. 'border-style': config.dividerType
  9. }">
  10. {{proxyValue}}
  11. </div>
  12. </template>
  13. <script>
  14. import { computed } from 'vue'
  15. import { formInputProps } from '../../form-input-props'
  16. import { useFormInput } from '@cip/components/hooks/form-input'
  17. export default {
  18. props: formInputProps,
  19. setup (props, context) {
  20. const formInput = useFormInput(props, context)
  21. const contentPosition = computed(() => {
  22. return props.config?.contentPosition ?? 'center'
  23. })
  24. const dividerClass = computed(() => {
  25. if (contentPosition.value === 'left') return 'divider-left'
  26. if (contentPosition.value === 'right') return 'divider-right'
  27. return ''
  28. })
  29. const proxyValue = computed(() => {
  30. return props.modelValue || props.config.defaultValue
  31. })
  32. return {
  33. ...formInput,
  34. contentPosition: contentPosition.value,
  35. dividerClass: dividerClass.value,
  36. proxyValue
  37. }
  38. }
  39. }
  40. </script>
  41. <style lang="less">
  42. .cip-divider{
  43. display: flex;
  44. align-items: center;
  45. border-style: solid;
  46. border-width: 0;
  47. border-color: #ebedf0;
  48. color: #969799;
  49. margin: 0;
  50. font-size: 14px;
  51. line-height: 24px;
  52. &::before, &::after{
  53. display: block;
  54. flex: 1;
  55. box-sizing: border-box;
  56. height: 1px;
  57. border-color: inherit;
  58. border-style: inherit;
  59. border-width: 2px 0 0;
  60. transform: scaleY(.5);
  61. content: "";
  62. }
  63. &::before{
  64. margin-right: 16px;
  65. }
  66. &::after{
  67. margin-left: 16px;
  68. }
  69. &.divider-left::before{
  70. max-width: 10%;
  71. }
  72. &.divider-right::after{
  73. max-width: 10%;
  74. }
  75. &.empty-divider{
  76. &::before, &::after{
  77. margin-right: 0px;
  78. margin-left: 0px;
  79. }
  80. }
  81. }
  82. </style>