|
| 1 | +// Copyright (c) Jupyter Development Team. |
| 2 | +// Copyright (c) Microsoft Corporation. |
| 3 | +// Distributed under the terms of the Modified BSD License. |
| 4 | + |
| 5 | +import type { ElementStyles } from '@microsoft/fast-element'; |
| 6 | +import { css } from '@microsoft/fast-element'; |
| 7 | +import type { FoundationElementTemplate } from '@microsoft/fast-foundation'; |
| 8 | +import { |
| 9 | + disabledCursor, |
| 10 | + display, |
| 11 | + focusVisible, |
| 12 | + forcedColorsStylesheetBehavior, |
| 13 | + ListboxElement, |
| 14 | + ListboxOption |
| 15 | +} from '@microsoft/fast-foundation'; |
| 16 | +import { SystemColors } from '@microsoft/fast-web-utilities'; |
| 17 | +import { |
| 18 | + controlCornerRadius, |
| 19 | + designUnit, |
| 20 | + disabledOpacity, |
| 21 | + fillColor, |
| 22 | + focusStrokeOuter, |
| 23 | + focusStrokeWidth, |
| 24 | + neutralStrokeRest, |
| 25 | + strokeWidth |
| 26 | +} from '@microsoft/fast-components'; |
| 27 | +import { heightNumber } from '../styles/size'; |
| 28 | + |
| 29 | +/** |
| 30 | + * Styles for Listbox |
| 31 | + * @public |
| 32 | + */ |
| 33 | +export const listboxStyles: FoundationElementTemplate<ElementStyles> = ( |
| 34 | + context, |
| 35 | + definition |
| 36 | +) => { |
| 37 | + const ListboxOptionTag = context.tagFor(ListboxOption); |
| 38 | + const hostContext = |
| 39 | + context.name === context.tagFor(ListboxElement) ? '' : '.listbox'; |
| 40 | + |
| 41 | + // The expression interpolations present in this block cause Prettier to generate |
| 42 | + // various formatting bugs. |
| 43 | + // prettier-ignore |
| 44 | + return css` |
| 45 | + ${!hostContext ? display('inline-flex') : ''} |
| 46 | +
|
| 47 | + :host ${hostContext} { |
| 48 | + background: ${fillColor}; |
| 49 | + border: calc(${strokeWidth} * 1px) solid ${neutralStrokeRest}; |
| 50 | + border-radius: calc(${controlCornerRadius} * 1px); |
| 51 | + box-sizing: border-box; |
| 52 | + flex-direction: column; |
| 53 | + padding: calc(${designUnit} * 1px) 0; |
| 54 | + } |
| 55 | +
|
| 56 | + ${!hostContext ? css` |
| 57 | + :host(:${focusVisible}:not([disabled])) { |
| 58 | + outline: none; |
| 59 | + } |
| 60 | +
|
| 61 | + :host(:focus-within:not([disabled])) { |
| 62 | + border-color: ${focusStrokeOuter}; |
| 63 | + box-shadow: 0 0 0 |
| 64 | + calc((${focusStrokeWidth} - ${strokeWidth}) * 1px) |
| 65 | + ${focusStrokeOuter} inset; |
| 66 | + } |
| 67 | +
|
| 68 | + :host([disabled]) ::slotted(*) { |
| 69 | + cursor: ${disabledCursor}; |
| 70 | + opacity: ${disabledOpacity}; |
| 71 | + pointer-events: none; |
| 72 | + } |
| 73 | + ` : ''} |
| 74 | +
|
| 75 | + ${hostContext || ':host([size])'} { |
| 76 | + max-height: calc( |
| 77 | + (var(--size) * ${heightNumber} + (${designUnit} * ${strokeWidth} * 2)) * 1px |
| 78 | + ); |
| 79 | + overflow-y: auto; |
| 80 | + } |
| 81 | +
|
| 82 | + :host([size="0"]) ${hostContext} { |
| 83 | + max-height: none; |
| 84 | + } |
| 85 | + `.withBehaviors( |
| 86 | + forcedColorsStylesheetBehavior( |
| 87 | + css` |
| 88 | + :host(:not([multiple]):${focusVisible}) ::slotted(${ListboxOptionTag}[aria-selected="true"]), |
| 89 | + :host([multiple]:${focusVisible}) ::slotted(${ListboxOptionTag}[aria-checked="true"]) { |
| 90 | + border-color: ${SystemColors.ButtonText}; |
| 91 | + box-shadow: 0 0 0 calc(${focusStrokeWidth} * 1px) inset ${SystemColors.HighlightText}; |
| 92 | + } |
| 93 | +
|
| 94 | + :host(:not([multiple]):${focusVisible}) ::slotted(${ListboxOptionTag}[aria-selected="true"]) { |
| 95 | + background: ${SystemColors.Highlight}; |
| 96 | + color: ${SystemColors.HighlightText}; |
| 97 | + fill: currentcolor; |
| 98 | + } |
| 99 | +
|
| 100 | + ::slotted(${ListboxOptionTag}[aria-selected="true"]:not([aria-checked="true"])) { |
| 101 | + background: ${SystemColors.Highlight}; |
| 102 | + border-color: ${SystemColors.HighlightText}; |
| 103 | + color: ${SystemColors.HighlightText}; |
| 104 | + } |
| 105 | + ` |
| 106 | + ) |
| 107 | + ); |
| 108 | +}; |
0 commit comments