library
Prebuilt pebble components: drop-in custom elements, no compiler needed
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runAucun
0Étoiles
0Forks
2Issues
| 1 | /* Vote: the two server forms of <pebble-vote>, side by side, as pill buttons. |
| 2 | |
| 3 | One sheet, two uses: the element adopts it as is (define's scoped: false), |
| 4 | and dist/vote.css is the same rules raw, for the page to <link> so the forms |
| 5 | look right before (or without) JS. So every selector starts at the tag: |
| 6 | that is its scope (inside @scope (tag) the tag itself would not match). |
| 7 | |
| 8 | State is attributes, never generated CSS: [aria-pressed="true"] on the |
| 9 | chosen button, [data-side="up" | "down"] on each button (the element writes |
| 10 | it; a server that wants the side's colour without JS writes it too), |
| 11 | [data-busy] and [data-mine] on the host, the class .bounce on the button |
| 12 | just pressed. |
| 13 | |
| 14 | Theming: every value is a --pebble-vote-* custom property with a fallback, |
| 15 | light and dark defaults chosen by prefers-color-scheme; page tokens |
| 16 | (--accent) inherit in. */ |
| 17 | |
| 18 | pebble-vote { |
| 19 | --_ink: var(--pebble-vote-ink, #1a1a1a); |
| 20 | --_surface: var(--pebble-vote-surface, #ffffff); |
| 21 | --_border: var(--pebble-vote-border, #d0d0d0); |
| 22 | --_up: var(--pebble-vote-up, #c92a2a); |
| 23 | --_up-wash: var(--pebble-vote-up-wash, #fff0f0); |
| 24 | --_down: var(--pebble-vote-down, #343a40); |
| 25 | --_down-wash: var(--pebble-vote-down-wash, #e9ecef); |
| 26 | --_focus: var(--pebble-vote-focus, var(--accent, #1971c2)); |
| 27 | |
| 28 | display: inline-flex; |
| 29 | flex-wrap: wrap; |
| 30 | align-items: center; |
| 31 | gap: var(--pebble-vote-gap, 0.5rem); |
| 32 | } |
| 33 | |
| 34 | @media (prefers-color-scheme: dark) { |
| 35 | pebble-vote { |
| 36 | --_ink: var(--pebble-vote-ink, #f1f3f5); |
| 37 | --_surface: var(--pebble-vote-surface, #1f1f1f); |
| 38 | --_border: var(--pebble-vote-border, #495057); |
| 39 | --_up: var(--pebble-vote-up, #ff8787); |
| 40 | --_up-wash: var(--pebble-vote-up-wash, #3b1d1d); |
| 41 | --_down: var(--pebble-vote-down, #ced4da); |
| 42 | --_down-wash: var(--pebble-vote-down-wash, #343a40); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | pebble-vote form { |
| 47 | display: contents; |
| 48 | } |
| 49 | |
| 50 | pebble-vote button { |
| 51 | --_side: var(--_up); |
| 52 | --_wash: var(--_up-wash); |
| 53 | |
| 54 | display: inline-flex; |
| 55 | align-items: center; |
| 56 | justify-content: center; |
| 57 | gap: 0.375rem; |
| 58 | box-sizing: border-box; |
| 59 | min-width: var(--pebble-vote-size, 44px); |
| 60 | min-height: var(--pebble-vote-size, 44px); |
| 61 | padding: 0 var(--pebble-vote-padding, 0.875rem); |
| 62 | border: 2px solid var(--_border); |
| 63 | border-radius: var(--pebble-vote-radius, 999px); |
| 64 | background: var(--_surface); |
| 65 | color: var(--_ink); |
| 66 | font: inherit; |
| 67 | font-size: var(--pebble-vote-font-size, 1rem); |
| 68 | font-variant-numeric: tabular-nums; |
| 69 | line-height: 1; |
| 70 | cursor: pointer; |
| 71 | touch-action: manipulation; |
| 72 | -webkit-tap-highlight-color: transparent; |
| 73 | |
| 74 | & svg, |
| 75 | & img { |
| 76 | width: 1.25em; |
| 77 | height: 1.25em; |
| 78 | flex: none; |
| 79 | } |
| 80 | |
| 81 | &[data-side="down"] { |
| 82 | --_side: var(--_down); |
| 83 | --_wash: var(--_down-wash); |
| 84 | } |
| 85 | |
| 86 | &[aria-pressed="true"] { |
| 87 | border-color: var(--_side); |
| 88 | background: var(--_wash); |
| 89 | color: var(--_side); |
| 90 | font-weight: 700; |
| 91 | } |
| 92 | |
| 93 | &:focus-visible { |
| 94 | outline: 3px solid var(--_focus); |
| 95 | outline-offset: 2px; |
| 96 | } |
| 97 | |
| 98 | &.bounce { |
| 99 | animation: pebble-vote-bounce 400ms ease-out; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | pebble-vote[data-busy] button { |
| 104 | cursor: progress; |
| 105 | } |
| 106 | |
| 107 | @media (prefers-reduced-motion: reduce) { |
| 108 | pebble-vote button.bounce { |
| 109 | animation: none; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* Named for the component: if an engine hoists keyframes out of @scope, the |
| 114 | name still cannot collide with a page's. */ |
| 115 | @keyframes pebble-vote-bounce { |
| 116 | 0% { |
| 117 | transform: scale(1); |
| 118 | } |
| 119 | 35% { |
| 120 | transform: scale(1.18); |
| 121 | } |
| 122 | 70% { |
| 123 | transform: scale(0.95); |
| 124 | } |
| 125 | 100% { |
| 126 | transform: scale(1); |
| 127 | } |
| 128 | } |