|
| 1 | +.SegmentedControl { |
| 2 | + display: inline-flex; |
| 3 | + |
| 4 | + /* TODO: use primitive `control.{small|medium}.size` when it is available */ |
| 5 | + height: 32px; |
| 6 | + padding: 0; |
| 7 | + margin: 0; |
| 8 | + font-size: var(--text-body-size-medium); |
| 9 | + background-color: var(--controlTrack-bgColor-rest); |
| 10 | + border: var(--borderWidth-thin) solid var(--controlTrack-borderColor-rest, transparent); |
| 11 | + border-radius: var(--borderRadius-medium); |
| 12 | + |
| 13 | + &:where([data-full-width]) { |
| 14 | + display: flex; |
| 15 | + width: 100%; |
| 16 | + } |
| 17 | + |
| 18 | + &:where([data-size='small']) { |
| 19 | + /* TODO: use primitive `control.{small|medium}.size` when it is available */ |
| 20 | + height: 28px; |
| 21 | + font-size: var(--text-body-size-small); |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +.Item { |
| 26 | + position: relative; |
| 27 | + display: block; |
| 28 | + /* stylelint-disable-next-line primer/spacing */ |
| 29 | + margin-top: -1px; |
| 30 | + /* stylelint-disable-next-line primer/spacing */ |
| 31 | + margin-bottom: -1px; |
| 32 | + flex-grow: 1; |
| 33 | + |
| 34 | + &:not(:last-child) { |
| 35 | + /* stylelint-disable-next-line primer/spacing */ |
| 36 | + margin-right: 1px; |
| 37 | + |
| 38 | + &::after { |
| 39 | + position: absolute; |
| 40 | + top: var(--base-size-8); |
| 41 | + right: calc(-1 * var(--base-size-2)); |
| 42 | + bottom: var(--base-size-8); |
| 43 | + width: 1px; |
| 44 | + content: ''; |
| 45 | + /* stylelint-disable-next-line primer/colors */ |
| 46 | + background-color: var(--borderColor-default); |
| 47 | + } |
| 48 | + |
| 49 | + &:has(+ [data-selected])::after, |
| 50 | + &:where([data-selected])::after { |
| 51 | + background-color: transparent; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + &:focus-within:has(:focus-visible) { |
| 56 | + background-color: transparent; |
| 57 | + } |
| 58 | + |
| 59 | + &:first-child { |
| 60 | + /* stylelint-disable-next-line primer/spacing */ |
| 61 | + margin-left: -1px; |
| 62 | + } |
| 63 | + |
| 64 | + &:last-child { |
| 65 | + /* stylelint-disable-next-line primer/spacing */ |
| 66 | + margin-right: -1px; |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +.Button { |
| 71 | + /* TODO: use primitive `primer.control.medium.paddingInline.normal` when it is available */ |
| 72 | + --segmented-control-button-inner-padding: 12px; |
| 73 | + --segmented-control-button-bg-inset: 4px; |
| 74 | + --segmented-control-outer-radius: var(--borderRadius-medium); |
| 75 | + |
| 76 | + width: 100%; |
| 77 | + height: 100%; |
| 78 | + /* stylelint-disable-next-line primer/spacing */ |
| 79 | + padding: var(--segmented-control-button-bg-inset); |
| 80 | + font-family: inherit; |
| 81 | + font-size: inherit; |
| 82 | + font-weight: var(--base-text-weight-normal); |
| 83 | + color: currentColor; |
| 84 | + cursor: pointer; |
| 85 | + background-color: transparent; |
| 86 | + border-color: transparent; |
| 87 | + border-width: 0; |
| 88 | + /* stylelint-disable-next-line primer/borders */ |
| 89 | + border-radius: var(--segmented-control-outer-radius); |
| 90 | + |
| 91 | + & svg { |
| 92 | + fill: var(--fgColor-muted); |
| 93 | + } |
| 94 | + |
| 95 | + /* fallback :focus state */ |
| 96 | + &:focus:not(:disabled) { |
| 97 | + outline: var(--base-size-2) solid var(--fgColor-accent); |
| 98 | + outline-offset: -1px; |
| 99 | + box-shadow: none; |
| 100 | + |
| 101 | + /* remove fallback :focus if :focus-visible is supported */ |
| 102 | + &:not(:focus-visible) { |
| 103 | + outline: solid 1px transparent; |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + /* default focus state */ |
| 108 | + &:focus-visible:not(:disabled) { |
| 109 | + outline: var(--base-size-2) solid var(--fgColor-accent); |
| 110 | + outline-offset: -1px; |
| 111 | + box-shadow: none; |
| 112 | + } |
| 113 | + |
| 114 | + /* stylelint-disable-next-line selector-max-specificity */ |
| 115 | + &:focus:focus-visible:not(:last-child)::after { |
| 116 | + /* fixes an issue where the focus outline shows over the pseudo-element */ |
| 117 | + width: 0; |
| 118 | + } |
| 119 | + |
| 120 | + @media (pointer: coarse) { |
| 121 | + &::before { |
| 122 | + position: absolute; |
| 123 | + top: 50%; |
| 124 | + right: 0; |
| 125 | + left: 0; |
| 126 | + min-height: 44px; |
| 127 | + content: ''; |
| 128 | + transform: translateY(-50%); |
| 129 | + } |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +.IconButton { |
| 134 | + /* TODO: use primitive `control.medium.size` when it is available instead of '32px' */ |
| 135 | + width: 32px; |
| 136 | + |
| 137 | + .SegmentedControl:where([data-full-width]) & { |
| 138 | + width: 100%; |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +.Content { |
| 143 | + display: flex; |
| 144 | + height: 100%; |
| 145 | + /* stylelint-disable-next-line primer/spacing */ |
| 146 | + padding-right: calc(var(--segmented-control-button-inner-padding) - var(--segmented-control-button-bg-inset)); |
| 147 | + /* stylelint-disable-next-line primer/spacing */ |
| 148 | + padding-left: calc(var(--segmented-control-button-inner-padding) - var(--segmented-control-button-bg-inset)); |
| 149 | + background-color: transparent; |
| 150 | + border-color: transparent; |
| 151 | + border-style: solid; |
| 152 | + border-width: var(--borderWidth-thin); |
| 153 | + |
| 154 | + /* |
| 155 | + innerRadius = outerRadius - distance/2 |
| 156 | + https://stackoverflow.com/questions/2932146/math-problem-determine-the-corner-radius-of-an-inner-border-based-on-outer-corn |
| 157 | + */ |
| 158 | + /* stylelint-disable-next-line primer/borders */ |
| 159 | + border-radius: calc(var(--segmented-control-outer-radius) - var(--segmented-control-button-bg-inset) / 2); |
| 160 | + align-items: center; |
| 161 | + justify-content: center; |
| 162 | +} |
| 163 | + |
| 164 | +.Button[aria-current='true'] { |
| 165 | + padding: 0; |
| 166 | + font-weight: var(--base-text-weight-semibold); |
| 167 | + |
| 168 | + .Content { |
| 169 | + /* stylelint-disable-next-line primer/spacing */ |
| 170 | + padding-right: var(--segmented-control-button-inner-padding); |
| 171 | + /* stylelint-disable-next-line primer/spacing */ |
| 172 | + padding-left: var(--segmented-control-button-inner-padding); |
| 173 | + background-color: var(--controlKnob-bgColor-rest); |
| 174 | + border-color: var(--controlKnob-borderColor-rest); |
| 175 | + /* stylelint-disable-next-line primer/borders */ |
| 176 | + border-radius: var(--segmented-control-outer-radius); |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +.Button:not([aria-current='true']) { |
| 181 | + &:hover .Content { |
| 182 | + background-color: var(--controlTrack-bgColor-hover); |
| 183 | + } |
| 184 | + |
| 185 | + &:active .Content { |
| 186 | + background-color: var(--controlTrack-bgColor-active); |
| 187 | + } |
| 188 | +} |
| 189 | + |
| 190 | +.Text::after { |
| 191 | + display: block; |
| 192 | + height: 0; |
| 193 | + overflow: hidden; |
| 194 | + font-weight: var(--base-text-weight-semibold); |
| 195 | + pointer-events: none; |
| 196 | + visibility: hidden; |
| 197 | + content: attr(data-text); |
| 198 | + user-select: none; |
| 199 | +} |
0 commit comments