segmented.scss 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. @use 'sass:map';
  2. @use 'mixins/mixins' as *;
  3. @use 'mixins/utils' as *;
  4. @use 'mixins/var' as *;
  5. @use 'common/var' as *;
  6. $segmented-border-radius: () !default;
  7. $segmented-border-radius: map.merge(
  8. (
  9. 'large': map.get($button-border-radius, 'large'),
  10. 'default': map.get($button-border-radius, 'default'),
  11. 'small': map.get($button-border-radius, 'small'),
  12. ),
  13. $segmented-border-radius
  14. );
  15. $segmented-font-size: () !default;
  16. $segmented-font-size: map.merge(
  17. (
  18. 'large': 16px,
  19. 'default': 14px,
  20. 'small': 14px,
  21. ),
  22. $segmented-font-size
  23. );
  24. $segmented-item-padding: () !default;
  25. $segmented-item-padding: map.merge(
  26. (
  27. 'large': 0 11px,
  28. 'default': 0 11px,
  29. 'small': 0 7px,
  30. ),
  31. $segmented-item-padding
  32. );
  33. $segmented-item-padding-vertical: () !default;
  34. $segmented-item-padding-vertical: map.merge(
  35. (
  36. 'large': 11px 11px,
  37. 'default':11px 11px,
  38. 'small': 7px 7px,
  39. ),
  40. $segmented-item-padding-vertical
  41. );
  42. .#{$namespace}-segmented--vertical {
  43. flex-direction: column;
  44. .#{$namespace}-segmented__item {
  45. padding: map.get($segmented-item-padding-vertical, 'default');
  46. }
  47. }
  48. @include b(segmented) {
  49. @include set-component-css-var('segmented', $segmented);
  50. }
  51. @include b(segmented) {
  52. display: inline-flex;
  53. align-items: stretch;
  54. min-height: map.get($input-height, 'default');
  55. background: getCssVar('segmented-bg-color');
  56. padding: getCssVar('segmented-padding');
  57. border-radius: map.get($segmented-border-radius, 'default');
  58. font-size: map.get($segmented-font-size, 'default');
  59. color: getCssVar('segmented-color');
  60. box-sizing: border-box;
  61. @include e(group) {
  62. display: flex;
  63. align-items: stretch;
  64. position: relative;
  65. width: 100%;
  66. }
  67. @include e(item-selected) {
  68. position: absolute;
  69. top: 0;
  70. left: 0;
  71. background: getCssVar('segmented-item-selected-bg-color');
  72. height: 100%;
  73. width: 10px;
  74. border-radius: calc(#{map.get($segmented-border-radius, 'default')} - 2px);
  75. transition: all 0.3s;
  76. pointer-events: none;
  77. @include when(disabled) {
  78. background: getCssVar('segmented-item-selected-disabled-bg-color');
  79. }
  80. @include when(focus-visible) {
  81. &:before {
  82. position: absolute;
  83. content: '';
  84. inset: 0;
  85. border-radius: inherit;
  86. outline: 2px solid getCssVar('segmented-item-selected-bg-color');
  87. outline-offset: 1px;
  88. }
  89. }
  90. }
  91. @include e(item) {
  92. display: flex;
  93. align-items: center;
  94. flex: 1;
  95. cursor: pointer;
  96. border-radius: calc(#{map.get($segmented-border-radius, 'default')} - 2px);
  97. padding: map.get($segmented-item-padding, 'default');
  98. &:not(.is-disabled):not(.is-selected):hover {
  99. color: getCssVar('segmented-item-hover-color');
  100. background: getCssVar('segmented-item-hover-bg-color');
  101. }
  102. &:not(.is-disabled):not(.is-selected):active {
  103. background: getCssVar('segmented-item-active-bg-color');
  104. }
  105. @include when(selected) {
  106. color: getCssVar('segmented-item-selected-color');
  107. &.is-disabled {
  108. color: getCssVar('segmented-item-selected-color');
  109. }
  110. }
  111. @include when(disabled) {
  112. cursor: not-allowed;
  113. color: getCssVar('segmented-item-disabled-color');
  114. }
  115. }
  116. @include e(item-input) {
  117. position: absolute;
  118. margin: 0;
  119. width: 0;
  120. height: 0;
  121. opacity: 0;
  122. pointer-events: none;
  123. }
  124. @include e(item-label) {
  125. flex: 1;
  126. text-align: center;
  127. line-height: normal;
  128. @include utils-ellipsis;
  129. transition: color 0.3s;
  130. z-index: 1;
  131. }
  132. @include when(block) {
  133. display: flex;
  134. .#{$namespace}-segmented__item {
  135. min-width: 0;
  136. }
  137. }
  138. @each $size in (large, small) {
  139. @include m($size) {
  140. min-height: map.get($input-height, $size);
  141. border-radius: map.get($segmented-border-radius, $size);
  142. font-size: map.get($segmented-font-size, $size);
  143. @include e(item-selected) {
  144. border-radius: calc(#{map.get($segmented-border-radius, $size)} - 2px);
  145. }
  146. .#{$namespace}-segmented--vertical {
  147. @include e(item) {
  148. padding: map.get($segmented-item-padding-vertical, $size);
  149. }
  150. }
  151. @include e(item) {
  152. border-radius: calc(#{map.get($segmented-border-radius, $size)} - 2px);
  153. padding: map.get($segmented-item-padding, $size);
  154. }
  155. }
  156. }
  157. }