|
| 1 | +import { |
| 2 | + BREAKPOINTS, |
| 3 | + mediaBelow, |
| 4 | + styleBuilder, |
| 5 | + themes, |
| 6 | +} from '@purestack/ts-style' |
| 7 | +import { defineComponent, html, type RefOrValue } from 'regor' |
| 8 | + |
| 9 | +export interface ComponentHeader { |
| 10 | + name: RefOrValue<string> |
| 11 | + summary: RefOrValue<string> |
| 12 | + source: RefOrValue<string> |
| 13 | + kind: RefOrValue<string> |
| 14 | + section?: RefOrValue<string> |
| 15 | + sectionHref?: RefOrValue<string> |
| 16 | +} |
| 17 | + |
| 18 | +export interface ComponentExample { |
| 19 | + label: RefOrValue<string> |
| 20 | + caption: RefOrValue<string> |
| 21 | +} |
| 22 | + |
| 23 | +export function defineComponentGuideComponents() { |
| 24 | + return { |
| 25 | + ComponentHeader: defineComponent<ComponentHeader>( |
| 26 | + html`<header class="component-header"> |
| 27 | + <div class="component-header__top"> |
| 28 | + <div class="component-header__identity"><code>{{ name }}</code><span>{{ kind }}</span></div> |
| 29 | + <nav class="component-header__links" aria-label="Component resources"> |
| 30 | + <a href="#api-reference">API <span aria-hidden="true">↗</span></a> |
| 31 | + <a :href="source" target="_blank" rel="noopener noreferrer">Source <span aria-hidden="true">↗</span></a> |
| 32 | + </nav> |
| 33 | + </div> |
| 34 | + <p class="component-header__summary">{{ summary }}</p> |
| 35 | + <a class="component-header__back" :href="sectionHref">{{ section }} <span aria-hidden="true">↗</span></a> |
| 36 | + </header>`, |
| 37 | + { |
| 38 | + props: ['name', 'summary', 'source', 'kind', 'section', 'sectionHref'], |
| 39 | + context: (head) => ({ |
| 40 | + ...head.props, |
| 41 | + section: head.props.section ?? 'Actions & feedback', |
| 42 | + sectionHref: head.props.sectionHref ?? '/components/actions/', |
| 43 | + }), |
| 44 | + }, |
| 45 | + ), |
| 46 | + ComponentExample: defineComponent<ComponentExample>( |
| 47 | + html`<section class="component-example" :aria-label="label"> |
| 48 | + <header class="component-example__heading"><span class="component-example__dot" aria-hidden="true"></span><strong>{{ label }}</strong><span class="component-example__tag">COMPOSITION</span></header> |
| 49 | + <div class="component-example__stage"><slot></slot></div> |
| 50 | + <p class="component-example__caption">{{ caption }}</p> |
| 51 | + </section>`, |
| 52 | + { props: ['label', 'caption'] }, |
| 53 | + ), |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +export function registerComponentGuideStyles() { |
| 58 | + themes.forEach((theme, palette) => { |
| 59 | + const root = styleBuilder.get(theme) |
| 60 | + const neutral = palette.semanticTone.neutral |
| 61 | + const accent = palette.semanticTone.accent |
| 62 | + root.select('.component-guide-card > .badge').css({ alignSelf: 'start' }) |
| 63 | + root.select('.component-header').css({ |
| 64 | + position: 'relative', |
| 65 | + overflow: 'hidden', |
| 66 | + padding: '1rem 1.25rem', |
| 67 | + margin: '0.75rem 0 1.5rem', |
| 68 | + border: `1px solid ${neutral.border.subtle}`, |
| 69 | + borderLeft: `3px solid ${accent.border.default}`, |
| 70 | + borderRadius: '0.75rem', |
| 71 | + background: `radial-gradient(ellipse at 100% 0%, ${accent.surface.rest.background}, transparent 70%), ${neutral.surface.rest.background}`, |
| 72 | + }) |
| 73 | + root.select('.component-header__top').css({ |
| 74 | + display: 'flex', |
| 75 | + flexWrap: 'wrap', |
| 76 | + alignItems: 'baseline', |
| 77 | + justifyContent: 'space-between', |
| 78 | + gap: '0.6rem 1.25rem', |
| 79 | + }) |
| 80 | + root.select('.component-header__back').css({ |
| 81 | + fontSize: '0.75rem', |
| 82 | + color: neutral.text.subtle, |
| 83 | + textDecoration: 'none', |
| 84 | + }) |
| 85 | + root.select('.component-header__identity').css({ |
| 86 | + display: 'flex', |
| 87 | + flexWrap: 'wrap', |
| 88 | + alignItems: 'baseline', |
| 89 | + gap: '0.4rem 0.75rem', |
| 90 | + minWidth: '0', |
| 91 | + }) |
| 92 | + root.select('.component-header__identity code').css({ |
| 93 | + color: accent.text.default, |
| 94 | + fontSize: '1rem', |
| 95 | + background: 'none', |
| 96 | + border: 'none', |
| 97 | + padding: '0', |
| 98 | + margin: '0', |
| 99 | + lineHeight: '1.4', |
| 100 | + overflowWrap: 'anywhere', |
| 101 | + }) |
| 102 | + root |
| 103 | + .select('.component-header__identity span, .component-example__tag') |
| 104 | + .css({ |
| 105 | + fontSize: '0.65rem', |
| 106 | + letterSpacing: '0.1em', |
| 107 | + textTransform: 'uppercase', |
| 108 | + color: neutral.text.subtle, |
| 109 | + }) |
| 110 | + root.select('.component-header__summary').css({ |
| 111 | + fontSize: '0.95rem', |
| 112 | + lineHeight: '1.6', |
| 113 | + margin: '0.6rem 0 0.4rem', |
| 114 | + }) |
| 115 | + root.select('.component-header__links').css({ |
| 116 | + display: 'flex', |
| 117 | + flexWrap: 'wrap', |
| 118 | + alignItems: 'baseline', |
| 119 | + gap: '0.75rem', |
| 120 | + flexShrink: '0', |
| 121 | + }) |
| 122 | + root.select('.component-header__links a').css({ |
| 123 | + fontSize: '0.75rem', |
| 124 | + fontWeight: '600', |
| 125 | + textDecoration: 'none', |
| 126 | + color: accent.text.default, |
| 127 | + }) |
| 128 | + root |
| 129 | + .select('.component-header a:hover') |
| 130 | + .css({ textDecoration: 'underline' }) |
| 131 | + root.select('.component-example').css({ |
| 132 | + margin: '1.5rem 0', |
| 133 | + border: `1px solid ${neutral.border.subtle}`, |
| 134 | + borderRadius: '1rem', |
| 135 | + background: neutral.surface.rest.background, |
| 136 | + }) |
| 137 | + root.select('.component-example__heading').css({ |
| 138 | + display: 'flex', |
| 139 | + flexWrap: 'wrap', |
| 140 | + alignItems: 'center', |
| 141 | + gap: '0.6rem', |
| 142 | + padding: '0.9rem 1.25rem', |
| 143 | + borderBottom: `1px solid ${neutral.border.subtle}`, |
| 144 | + fontSize: '0.8rem', |
| 145 | + }) |
| 146 | + root.select('.component-example__dot').css({ |
| 147 | + width: '0.5rem', |
| 148 | + height: '0.5rem', |
| 149 | + borderRadius: '50%', |
| 150 | + background: accent.text.default, |
| 151 | + }) |
| 152 | + root.select('.component-example__tag').css({ marginLeft: 'auto' }) |
| 153 | + root.select('.component-example__stage').css({ |
| 154 | + padding: 'clamp(1rem, 3vw, 2rem)', |
| 155 | + background: `radial-gradient(${neutral.border.subtle} 1px, transparent 1px)`, |
| 156 | + backgroundSize: '16px 16px', |
| 157 | + minWidth: '0', |
| 158 | + }) |
| 159 | + root.select('.component-example__caption').css({ |
| 160 | + margin: '0', |
| 161 | + padding: '0.9rem 1.25rem', |
| 162 | + borderTop: `1px solid ${neutral.border.subtle}`, |
| 163 | + fontSize: '0.8rem', |
| 164 | + color: neutral.text.subtle, |
| 165 | + lineHeight: '1.6', |
| 166 | + }) |
| 167 | + root |
| 168 | + .select('.component-preview-stage') |
| 169 | + .css({ padding: 'clamp(1rem, 3vw, 2rem)', minWidth: '0' }) |
| 170 | + root.select('.component-appearance-grid').css({ |
| 171 | + display: 'grid', |
| 172 | + gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 14rem), 1fr))', |
| 173 | + gap: '1rem', |
| 174 | + alignItems: 'start', |
| 175 | + }) |
| 176 | + root.select('.component-appearance-cell').css({ |
| 177 | + display: 'flex', |
| 178 | + flexDirection: 'column', |
| 179 | + alignItems: 'stretch', |
| 180 | + gap: '1rem', |
| 181 | + padding: '1rem', |
| 182 | + minWidth: '0', |
| 183 | + border: `1px solid ${neutral.border.subtle}`, |
| 184 | + borderRadius: '0.75rem', |
| 185 | + background: neutral.surface.rest.background, |
| 186 | + }) |
| 187 | + root.select('.component-appearance-cell > code').css({ |
| 188 | + fontSize: '0.75rem', |
| 189 | + color: neutral.text.subtle, |
| 190 | + background: 'none', |
| 191 | + border: 'none', |
| 192 | + padding: '0', |
| 193 | + }) |
| 194 | + root |
| 195 | + .select('.component-appearance-cell > .btn-group__dropdown') |
| 196 | + .css({ alignSelf: 'start' }) |
| 197 | + root.select('.component-directory-lead').css({ |
| 198 | + fontSize: 'clamp(1.4rem, 3vw, 2rem)', |
| 199 | + lineHeight: '1.35', |
| 200 | + fontWeight: '600', |
| 201 | + maxWidth: '34rem', |
| 202 | + color: accent.text.default, |
| 203 | + }) |
| 204 | + root.select('.component-recipe').css({ |
| 205 | + padding: '1.5rem', |
| 206 | + border: `1px solid ${neutral.border.subtle}`, |
| 207 | + borderRadius: '0.85rem', |
| 208 | + background: neutral.surface.rest.background, |
| 209 | + boxShadow: '0 8px 24px rgb(0 0 0 / 0.06)', |
| 210 | + }) |
| 211 | + root |
| 212 | + .select('.component-recipe h3') |
| 213 | + .css({ margin: '0.4rem 0 0.75rem', fontSize: '1.25rem' }) |
| 214 | + root |
| 215 | + .select('.component-recipe > p') |
| 216 | + .css({ margin: '0.5rem 0 1.25rem', color: neutral.text.subtle }) |
| 217 | + root.select('.component-guide-grid').css({ |
| 218 | + display: 'grid', |
| 219 | + gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', |
| 220 | + gap: '1rem', |
| 221 | + }) |
| 222 | + root.select('.component-guide-card').css({ |
| 223 | + display: 'flex', |
| 224 | + flexDirection: 'column', |
| 225 | + padding: '1.5rem', |
| 226 | + border: `1px solid ${neutral.border.subtle}`, |
| 227 | + borderRadius: '1rem', |
| 228 | + background: neutral.surface.rest.background, |
| 229 | + minWidth: '0', |
| 230 | + }) |
| 231 | + root |
| 232 | + .select('.component-guide-card h3') |
| 233 | + .css({ margin: '1.25rem 0 0.5rem', overflowWrap: 'anywhere' }) |
| 234 | + root |
| 235 | + .select('.component-guide-card > p') |
| 236 | + .css({ color: neutral.text.subtle, fontSize: '0.9rem', flexGrow: '1' }) |
| 237 | + root.select('.component-guide-card__preview').css({ |
| 238 | + display: 'flex', |
| 239 | + alignItems: 'center', |
| 240 | + justifyContent: 'center', |
| 241 | + flexWrap: 'wrap', |
| 242 | + gap: '0.5rem', |
| 243 | + minHeight: '6rem', |
| 244 | + padding: '1rem', |
| 245 | + borderRadius: '0.75rem', |
| 246 | + background: accent.surface.rest.background, |
| 247 | + }) |
| 248 | + root.select('.component-guide-card > a').css({ |
| 249 | + fontWeight: '600', |
| 250 | + fontSize: '0.85rem', |
| 251 | + color: accent.text.default, |
| 252 | + }) |
| 253 | + root |
| 254 | + .media(mediaBelow(BREAKPOINTS.md)) |
| 255 | + .select('.component-guide-grid') |
| 256 | + .css({ gridTemplateColumns: 'minmax(0, 1fr)' }) |
| 257 | + }) |
| 258 | +} |
0 commit comments