Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 458x 458x 458x 458x 458x 458x 458x 462x 458x 34x 458x 4x 2x 2x 2x 458x 16x 16x 16x 16x 486x 2x 2x 2x 2x 2x 2x 2x 2x 34x 34x 34x 34x 16x 16x | <template> <button ref="button" class="cdx-button" :class="rootClasses" @keydown.space.enter.prevent="onKeyDown" @keyup.space.enter="onKeyUp" @click="onClick" > <!-- @slot Button content --> <slot /> </button> </template> <script lang="ts"> import { PropType, defineComponent, ref, computed } from 'vue'; import { ButtonActions, ButtonWeights, ButtonSizes } from '../../constants'; import { ButtonAction, ButtonWeight, ButtonSize } from '../../types'; import useIconOnlyButton from '../../composables/useIconOnlyButton'; import { makeStringTypeValidator } from '../../utils/stringTypeValidator'; const buttonActionValidator = makeStringTypeValidator( ButtonActions ); const buttonWeightValidator = makeStringTypeValidator( ButtonWeights ); const buttonSizeValidator = makeStringTypeValidator( ButtonSizes ); /** * A control that triggers an action when the user clicks or taps on it. */ export default defineComponent( { name: 'CdxButton', props: { /** * The kind of action that will be taken on click. * * @values 'default', 'progressive', 'destructive' */ action: { type: String as PropType<ButtonAction>, default: 'default', validator: buttonActionValidator }, /** * Visual prominence of the button. * * @values 'normal', 'primary', 'quiet' */ weight: { type: String as PropType<ButtonWeight>, default: 'normal', validator: buttonWeightValidator }, /** * Button size. * * Most buttons should use the default medium size. In rare cases the large size should * be used, for example to make icon-only buttons larger on touchscreens. * * @values 'medium', 'large' */ size: { type: String as PropType<ButtonSize>, default: 'medium', validator: buttonSizeValidator } }, emits: [ 'click' ], setup( props, { emit, slots, attrs } ) { const button = ref<HTMLButtonElement>(); const isIconOnly = useIconOnlyButton( slots.default, attrs, 'CdxButton' ); // Support: Firefox (space), all (enter) // Whether the button is being pressed via the space or enter key. Needed to apply // consistent active styles across browsers. For mousedown/mouseup, the browser's native // :active state will suffice. const isActive = ref( false ); const rootClasses = computed( () => ( { [ `cdx-button--action-${ props.action }` ]: true, [ `cdx-button--weight-${ props.weight }` ]: true, [ `cdx-button--size-${ props.size }` ]: true, 'cdx-button--framed': props.weight !== 'quiet', 'cdx-button--icon-only': isIconOnly.value, 'cdx-button--is-active': isActive.value } ) ); const onClick = ( event: Event ) => { emit( 'click', event ); }; const setActive = ( active: boolean ) => { isActive.value = active; }; function onKeyDown() { setActive( true ); } function onKeyUp() { setActive( false ); // Trigger a click. We do this instead of emitting a click event to trigger native // events, like form submission. button.value?.click(); } return { button, rootClasses, onClick, onKeyDown, onKeyUp }; } } ); </script> <style lang="less"> @import ( reference ) '@wikimedia/codex-design-tokens/theme-wikimedia-ui.less'; @import ( reference ) '../../themes/mixins/button.less'; /* stylelint-disable max-nesting-depth */ .cdx-button { // Mixin for common base styles for buttons. .cdx-mixin-button(); // Target both a CSS-only icon and a Vue icon, which could be included in the slot. .cdx-button__icon, .cdx-icon { // TODO: The vertical alignment in the current DOM structure is not ideal. The icon should // be aligned with the text baseline, but this doesn't work well in our multi font-size // theme setup in MediaWiki. This is a temporary compromise to be resolved with either // theme-specific CSS or a DOM structure change. See T326900. vertical-align: middle; } // Vue icon. .cdx-icon { // Any icons used in the button content should have the color of the surrounding text // This overrides the color rule in Icon.vue, and ensures that the rules below changing the // text color for progressive and destructive buttons also apply to icons. color: inherit; } // This class can be applied to inline elements other than `<button>`, like `<a>` or `<label`>. // We do not encourage this, but it is needed for some legacy code and progressive enhancements. &--fake-button { // In case it's a link. &, &:hover, &:focus { text-decoration: none; } } // Styles for enabled buttons of all weights and actions. // The class is included to enable these styles for elements other than <button>. &:enabled, &.cdx-button--fake-button--enabled { background-color: @background-color-interactive-subtle; color: @color-base; border-color: @border-color-base; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-base ); } &:hover { background-color: @background-color-base; color: @color-base--hover; // Use hand cursor. This is nonstandard for a button but allows for a visible // interactivity distinction from the disabled state. cursor: @cursor-base--hover; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-base--hover ); } } &:active, &.cdx-button--is-active { background-color: @background-color-interactive; color: @color-emphasized; border-color: @border-color-interactive; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-emphasized ); } } &:focus { // Set the standard focus `outline` transparent. A `border` and `box-shadow` visual // focus is added above for common rendering. // In Windows high contrast mode the transparent outline becomes visible. // As vendor stylesheets set the outline on `:focus`, we need to follow here too and // can't rely on the next selector to override it. outline: @outline-base--focus; } // Amplify 'interaction' feeling when pressed, by not setting focus “outline” style while // in active state. &:focus:not( :active ):not( .cdx-button--is-active ) { border-color: @border-color-progressive--focus; box-shadow: @box-shadow-inset-small @box-shadow-color-progressive--focus; } // Normal progressive buttons. &.cdx-button--action-progressive { color: @color-progressive; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-progressive ); } &:hover { color: @color-progressive--hover; border-color: @border-color-progressive--hover; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-progressive--hover ); } } &:active, &.cdx-button--is-active { background-color: @background-color-progressive-subtle; color: @color-progressive--active; border-color: @border-color-progressive--active; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-progressive--active ); } } // `:focus` styles covered in `.cdx-button` selector above. // `color` inherited from `:enabled` rule. } // Normal destructive buttons. &.cdx-button--action-destructive { color: @color-destructive; /* stylelint-disable-next-line no-descending-specificity */ .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-destructive ); } &:hover { color: @color-destructive--hover; border-color: @border-color-destructive--hover; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-destructive--hover ); } } &:active, &.cdx-button--is-active { background-color: @background-color-destructive-subtle; color: @color-destructive--active; border-color: @border-color-destructive--active; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-destructive--active ); } } &:focus:not( :active ):not( .cdx-button--is-active ) { border-color: @border-color-destructive--focus; box-shadow: @box-shadow-inset-small @box-shadow-color-destructive--focus; } } // Primary buttons. &.cdx-button--weight-primary { // Progressive primary buttons. &.cdx-button--action-progressive { background-color: @background-color-progressive; color: @color-inverted-fixed; border-color: @border-color-progressive; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-inverted-fixed ); } &:hover { background-color: @background-color-progressive--hover; border-color: @border-color-progressive--hover; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-inverted-fixed ); } } &:active, &.cdx-button--is-active { background-color: @background-color-progressive--active; border-color: @border-color-progressive--active; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-inverted-fixed ); } } &:focus:not( :active ):not( .cdx-button--is-active ) { border-color: @border-color-progressive--focus; // Make `box-shadow` feature a `1px` White inset outline with a value // combination. /* stylelint-disable-next-line stylistic/declaration-colon-newline-after, stylistic/value-list-comma-newline-after */ box-shadow: @box-shadow-inset-small @box-shadow-color-progressive--focus, @box-shadow-inset-medium @box-shadow-color-inverted; } } // Destructive primary buttons. &.cdx-button--action-destructive { background-color: @background-color-destructive; color: @color-inverted-fixed; border-color: @border-color-destructive; /* stylelint-disable-next-line no-descending-specificity */ .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-inverted-fixed ); } &:hover { background-color: @background-color-destructive--hover; border-color: @border-color-destructive--hover; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-inverted-fixed ); } } &:active, &.cdx-button--is-active { background-color: @background-color-destructive--active; border-color: @border-color-destructive--active; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-inverted-fixed ); } } &:focus:not( :active ):not( .cdx-button--is-active ) { // While Codex tokens feature `background-color-destructive--focus` it's not // necessary to duplicate it, as `background-color` is inherited. border-color: @border-color-destructive--focus; // Make `box-shadow` feature a `1px` White inset outline with a value // combination. /* stylelint-disable-next-line stylistic/declaration-colon-newline-after, stylistic/value-list-comma-newline-after */ box-shadow: @box-shadow-inset-small @box-shadow-color-destructive--focus, @box-shadow-inset-medium @box-shadow-color-inverted; } } } // Quiet buttons. &.cdx-button--weight-quiet { // Reset `<button>` default background color. background-color: @background-color-transparent; border-color: @border-color-transparent; &:hover { background-color: @background-color-button-quiet--hover; } &:active, &.cdx-button--is-active { background-color: @background-color-button-quiet--active; color: @color-emphasized; border-color: @border-color-interactive; /* stylelint-disable-next-line no-descending-specificity */ .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-emphasized ); } } // `:focus` styles are the same as normal buttons. // Progressive quiet buttons. &.cdx-button--action-progressive { color: @color-progressive; /* stylelint-disable-next-line no-descending-specificity */ .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-progressive ); } &:hover { background-color: @background-color-progressive-subtle; color: @color-progressive--hover; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-progressive--hover ); } } &:active, &.cdx-button--is-active { background-color: @background-color-progressive--active; color: @color-inverted-fixed; border-color: @border-color-progressive--active; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-inverted ); } } // `:focus` styles are the same as normal progressive buttons. // `color` inherited from `:enabled` rule. } // Destructive quiet buttons. &.cdx-button--action-destructive { color: @color-destructive; /* stylelint-disable-next-line no-descending-specificity */ .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-destructive ); } &:hover { background-color: @background-color-destructive-subtle; color: @color-destructive--hover; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-destructive--hover ); } } &:active, &.cdx-button--is-active { background-color: @background-color-destructive--active; color: @color-inverted-fixed; border-color: @border-color-destructive--active; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-inverted ); } } &:focus:not( :active ):not( .cdx-button--is-active ) { border-color: @border-color-destructive--focus; box-shadow: @box-shadow-inset-small @box-shadow-color-destructive--focus; } } } } // Disabled styles all buttons. // These are the same for everything except quiet buttons. /* stylelint-disable no-descending-specificity */ &:disabled, &.cdx-button--fake-button--disabled { background-color: @background-color-disabled; color: @color-disabled-emphasized; border-color: @border-color-transparent; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-inverted ); } // Disabled quiet buttons. &.cdx-button--weight-quiet { background-color: @background-color-transparent; color: @color-disabled; .cdx-button__icon { .cdx-mixin-button-css-icon-fallback-color( @color-disabled ); } } } /* stylelint-enable no-descending-specificity */ } /* stylelint-enable max-nesting-depth */ </style> |