feat(ui): add native control CSS system + button/text/tab examples (#1267)

This commit is contained in:
Alex
2026-05-12 22:05:47 +01:00
committed by GitHub
parent 82704a26ae
commit a0a710079b
28 changed files with 771 additions and 87 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ body {
min-height: 100%;
margin: 0;
padding: 0;
background-color: var(--app-background);
background-color: var(--surface-app);
color: var(--text-color);
font-family: var(--font-family), serif;
-webkit-font-smoothing: antialiased;
@@ -35,7 +35,7 @@ body {
html,
body {
background-color: var(--page-background);
background-color: var(--surface-page);
}
}
+136
View File
@@ -0,0 +1,136 @@
.app-button {
--app-button-height: var(--control-height);
--app-button-padding-x: var(--control-padding-x);
--app-button-radius: var(--control-radius);
--app-button-icon-size: var(--control-icon-size);
--app-button-color: var(--text-color);
--app-button-bg: var(--control-bg);
--app-button-bg-hover: var(--control-bg-hover);
--app-button-border: var(--control-border);
--app-button-border-hover: var(--control-border-hover);
display: inline-flex;
position: relative;
align-items: center;
justify-content: center;
flex-shrink: 0;
gap: var(--control-gap);
box-sizing: border-box;
min-width: var(--app-button-height);
height: var(--app-button-height);
padding: 0 var(--app-button-padding-x);
border: 1px solid var(--app-button-border);
border-radius: var(--app-button-radius);
background: var(--app-button-bg);
background-clip: padding-box;
color: var(--app-button-color);
font: inherit;
font-size: var(--text-base);
font-weight: 500;
line-height: 1;
text-decoration: none;
white-space: nowrap;
cursor: pointer;
transition:
background var(--transition-fast),
border-color var(--transition-fast),
color var(--transition-fast),
transform var(--transition-fast);
&:hover {
background: var(--app-button-bg-hover);
border-color: var(--app-button-border-hover);
}
&:active {
transform: translateY(1px);
}
&:focus-visible {
outline: 2px solid var(--primary-color);
outline-offset: 2px;
}
&:disabled,
&[aria-disabled="true"] {
pointer-events: none;
opacity: var(--control-disabled-opacity);
}
.pi {
position: relative;
z-index: 1;
flex-shrink: 0;
font-size: var(--app-button-icon-size);
line-height: 1;
transition: transform var(--transition-fast);
}
span {
position: relative;
z-index: 1;
transition: transform var(--transition-fast);
}
}
.app-button-primary {
--app-button-bg: var(--control-primary-bg);
--app-button-bg-hover: var(--control-primary-bg-hover);
--app-button-border: var(--control-primary-border);
--app-button-border-hover: var(--control-primary-border-hover);
--app-button-color: var(--primary-color);
}
.app-button-danger {
--app-button-border: var(--danger-color);
--app-button-border-hover: var(--danger-hover-color);
}
.app-button-sm {
--app-button-height: var(--control-height-sm);
--app-button-padding-x: var(--control-padding-x-sm);
--app-button-icon-size: var(--control-icon-size-sm);
font-size: var(--text-sm);
}
.app-button-icon {
width: var(--app-button-height);
padding: 0;
background: transparent;
border: 0;
&::before {
content: "";
position: absolute;
inset: 0;
z-index: 0;
box-sizing: border-box;
border: 1px solid var(--app-button-border);
border-radius: inherit;
background: var(--app-button-bg);
background-clip: padding-box;
transition:
background var(--transition-fast),
border-color var(--transition-fast),
transform var(--transition-fast);
}
&:hover {
background: transparent;
&::before {
background: var(--app-button-bg-hover);
border-color: var(--app-button-border-hover);
}
}
&:active {
transform: none;
&::before,
.pi {
transform: translateY(1px);
}
}
}
@@ -0,0 +1,55 @@
.app-control-group {
--app-control-group-radius: var(--control-radius);
display: flex;
align-items: stretch;
width: 100%;
> * {
border-radius: 0;
}
> .app-text-field {
flex: 1 1 auto;
min-width: 0;
}
> * + * {
margin-left: -1px;
}
> :first-child {
border-top-left-radius: var(--app-control-group-radius);
border-bottom-left-radius: var(--app-control-group-radius);
}
> :last-child {
border-top-right-radius: var(--app-control-group-radius);
border-bottom-right-radius: var(--app-control-group-radius);
}
> .app-button {
--app-button-padding-x: 1rem;
}
> .app-button-icon {
width: calc(var(--app-button-height) + 0.375rem);
}
> .app-button-primary {
z-index: 1;
}
> .app-text-field:hover,
> .app-text-field:focus,
> .app-button:hover,
> .app-button:focus-visible,
> .app-button:active {
z-index: 2;
}
}
.app-control-group-inline {
display: inline-flex;
width: auto;
}
+11 -54
View File
@@ -24,16 +24,16 @@
.menu-panel,
.user-account-popover {
--menu-panel-padding: 4px;
--menu-panel-padding: var(--space-1);
--menu-panel-gap: 1px;
--menu-panel-min-width: 12rem;
--menu-panel-radius: 8px;
--menu-item-padding-block: 4px;
--menu-item-padding-inline: 10px;
--menu-item-min-height: 28px;
--menu-item-gap: 8px;
--menu-item-gap: var(--control-gap);
--menu-item-radius: 5px;
--menu-item-icon-size: 16px;
--menu-item-focus-ring: var(--control-focus-ring-color);
--menu-item-danger-bg-hover: color-mix(in srgb, var(--p-red-500) 12%, transparent);
}
.menu-panel {
@@ -42,9 +42,9 @@
gap: var(--menu-panel-gap);
min-width: var(--menu-panel-min-width);
padding: var(--menu-panel-padding);
background: var(--page-background);
background: var(--surface-page);
border: 1px solid var(--border-color);
border-radius: var(--menu-panel-radius);
border-radius: var(--control-radius);
box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
color: var(--text-color);
font: inherit;
@@ -78,7 +78,7 @@
.menu-panel .menu-item:focus-visible,
.user-account-popover .menu-item:focus-visible {
background-color: var(--surface-hover);
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary-color) 50%, transparent);
box-shadow: inset 0 0 0 1px var(--menu-item-focus-ring);
outline: none;
}
@@ -95,8 +95,8 @@
align-items: center;
justify-content: center;
flex-shrink: 0;
width: var(--menu-item-icon-size);
height: var(--menu-item-icon-size);
width: var(--control-icon-size);
height: var(--control-icon-size);
font-size: var(--text-base);
color: var(--surface-500);
}
@@ -127,9 +127,8 @@
flex-direction: column;
width: min(17.5rem, calc(100vw - 1rem));
overflow: hidden;
background: var(--page-background);
border: 1px solid var(--border-color);
border-radius: var(--menu-panel-radius);
border-radius: var(--control-radius);
box-shadow:
0 18px 48px rgb(0 0 0 / 28%),
0 4px 16px rgb(0 0 0 / 18%);
@@ -144,7 +143,6 @@
box-sizing: border-box;
width: 100%;
padding: 0.75rem;
background: color-mix(in srgb, var(--surface-hover), var(--page-background) 35%);
border-bottom: 1px solid var(--border-color);
}
@@ -207,45 +205,6 @@
gap: 0.5rem;
}
.user-account-popover .user-account-popover-settings,
.user-account-popover .user-account-popover-update {
display: inline-flex;
align-items: center;
justify-content: center;
align-self: flex-start;
gap: var(--menu-item-gap);
min-height: var(--menu-item-min-height);
padding: var(--menu-item-padding-block) var(--menu-item-padding-inline);
border: 1px solid var(--border-color);
border-radius: var(--menu-item-radius);
background: transparent;
color: var(--text-color);
font: inherit;
font-weight: 600;
text-decoration: none;
cursor: pointer;
}
.user-account-popover .user-account-popover-settings:hover,
.user-account-popover .user-account-popover-settings:focus-visible {
background: var(--surface-hover);
color: var(--text-color);
outline: none;
}
.user-account-popover .user-account-popover-update {
border-color: color-mix(in srgb, var(--primary-color) 30%, transparent);
background: color-mix(in srgb, var(--primary-color) 18%, transparent);
color: var(--primary-color);
}
.user-account-popover .user-account-popover-update:hover,
.user-account-popover .user-account-popover-update:focus-visible {
background: color-mix(in srgb, var(--primary-color) 26%, transparent);
color: var(--primary-color);
outline: none;
}
.user-account-popover-body {
display: flex;
flex-direction: column;
@@ -268,14 +227,12 @@
color: var(--p-red-400);
}
.user-account-popover .user-account-popover-settings i,
.user-account-popover .user-account-popover-update i,
.user-account-popover .user-account-popover-logout i {
color: currentcolor;
}
.user-account-popover .user-account-popover-logout:hover,
.user-account-popover .user-account-popover-logout:focus-visible {
background: color-mix(in srgb, var(--p-red-500) 12%, transparent);
background: var(--menu-item-danger-bg-hover);
outline: none;
}
+1 -1
View File
@@ -13,7 +13,7 @@
min-height: 100%;
padding: var(--page-gutter-block) var(--page-gutter-inline);
overflow: auto;
background-color: var(--page-background);
background-color: var(--surface-page);
color: var(--text-color);
}
+218
View File
@@ -0,0 +1,218 @@
app-tabs {
display: block;
}
.app-tabs-root {
display: contents;
}
.app-tabs {
position: relative;
display: flex;
align-items: center;
min-width: 0;
}
.app-tabs-indicator {
position: absolute;
left: 0;
pointer-events: none;
width: 0;
opacity: 0;
}
.app-tabs.is-measured .app-tabs-indicator {
opacity: 1;
}
.app-tabs.is-animated .app-tabs-indicator {
transition:
transform 220ms cubic-bezier(0.4, 0, 0.2, 1),
width 220ms cubic-bezier(0.4, 0, 0.2, 1);
}
.app-tab {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
gap: var(--control-gap);
box-sizing: border-box;
border: 0;
background: none;
color: var(--text-color-secondary);
font-size: 0.9375rem;
font-weight: 500;
line-height: 1;
white-space: nowrap;
text-align: center;
cursor: pointer;
transition:
color var(--transition-fast),
background-color var(--transition-fast),
transform var(--transition-fast);
&:hover {
color: var(--text-color);
}
&:active {
transform: translateY(1px);
}
&:focus-visible {
outline: 2px solid var(--primary-color);
outline-offset: 2px;
}
&[aria-selected="true"]:focus-visible {
outline: none;
}
}
.app-tab-icon {
font-size: 0.875em;
line-height: 1;
flex-shrink: 0;
}
.app-tab-label {
line-height: 1;
}
app-tabs.placement-below {
display: flex;
align-items: flex-start;
height: var(--app-tabs-row-height, 3.5rem);
padding: 0.25rem 2rem 0;
@media (width <= 767px) {
padding: 0.25rem 1rem 0;
}
}
app-tabs.variant-underline {
--app-tabs-divider: color-mix(in srgb, var(--surface-border) 70%, transparent);
padding: 0;
.app-tabs {
align-items: stretch;
width: 100%;
height: 100%;
gap: 1.5rem;
padding: 0 2rem;
&::after {
content: "";
position: absolute;
right: 2rem;
bottom: 0;
left: 2rem;
height: 1px;
background: var(--app-tabs-divider);
pointer-events: none;
}
@media (width <= 767px) {
gap: 1rem;
padding: 0 1rem;
overflow-x: auto;
scrollbar-width: none;
&::after {
right: 1rem;
left: 1rem;
}
&::-webkit-scrollbar {
display: none;
}
}
}
.app-tab {
min-width: 5rem;
padding: 0 1rem;
@media (width <= 767px) {
flex: 1 1 0;
min-width: 4rem;
padding: 0 0.875rem;
}
&[aria-selected="true"] {
color: var(--text-color);
&::before {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 2px;
background: var(--primary-color);
border-radius: 2px 2px 0 0;
z-index: 1;
}
}
}
.app-tabs.is-measured .app-tab[aria-selected="true"]::before {
display: none;
}
.app-tabs-indicator {
bottom: 0;
height: 2px;
background: var(--primary-color);
border-radius: 2px 2px 0 0;
z-index: 1;
}
}
app-tabs.variant-segmented {
.app-tabs {
gap: 0.125rem;
padding: var(--space-1);
border-radius: var(--radius-lg);
background: var(--control-bg);
@media (width <= 767px) {
overflow-x: auto;
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
}
.app-tab {
height: 2rem;
padding: 0 1rem;
border-radius: var(--control-radius);
&:hover:not([aria-selected="true"]) {
background: var(--surface-hover);
color: var(--text-color);
}
&[aria-selected="true"] {
color: var(--primary-color);
}
}
.app-tabs.is-measured .app-tab[aria-selected="true"] {
background: transparent;
}
.app-tabs-indicator {
top: var(--space-1);
bottom: var(--space-1);
box-sizing: border-box;
background: var(--control-primary-bg);
border-radius: var(--control-radius);
box-shadow: 0 0 0 1px var(--control-primary-border);
}
}
@@ -0,0 +1,47 @@
.app-text-field {
--app-text-field-height: var(--control-height);
--app-text-field-padding-x: var(--control-padding-x);
--app-text-field-radius: var(--control-radius);
--app-text-field-color: var(--text-color);
--app-text-field-bg: var(--control-bg);
--app-text-field-border: var(--control-border);
--app-text-field-border-hover: var(--control-border-hover);
--app-text-field-border-focus: var(--control-focus-border);
appearance: none;
display: block;
box-sizing: border-box;
width: 100%;
min-width: 0;
height: var(--app-text-field-height);
padding: 0 var(--app-text-field-padding-x);
border: 1px solid var(--app-text-field-border);
border-radius: var(--app-text-field-radius);
background: var(--app-text-field-bg);
background-clip: padding-box;
color: var(--app-text-field-color);
font: inherit;
font-size: var(--text-base);
line-height: 1.5;
transition:
background var(--transition-fast),
border-color var(--transition-fast);
&::placeholder {
color: var(--text-muted-color);
}
&:hover:not(:focus) {
border-color: var(--app-text-field-border-hover);
}
&:focus {
border-color: var(--app-text-field-border-focus);
outline: none;
}
&:disabled {
pointer-events: none;
opacity: var(--control-disabled-opacity);
}
}
+38 -4
View File
@@ -55,6 +55,8 @@
--primary-hover-color: var(--primary-300);
--primary-text-color: var(--primary-400);
--primary-text-color-dark: var(--primary-900);
--danger-color: #ef4444;
--danger-hover-color: #f87171;
/* Text */
--text-color: #ffffff;
@@ -64,13 +66,45 @@
--high-contrast-text-color: #ffffff;
/* App surfaces */
--app-background: #0d1012;
--page-background: color-mix(in srgb, var(--surface-900) 82%, var(--surface-950));
--surface-app: #0d1012;
--surface-page: color-mix(in srgb, var(--surface-900) 82%, var(--surface-950));
--surface-content: #1a1e21;
--surface-card: color-mix(in srgb, var(--surface-900) 62%, var(--surface-800));
--surface-toolbar: color-mix(in srgb, var(--app-background) 70%, var(--surface-content));
--surface-toolbar: color-mix(in srgb, var(--surface-app) 70%, var(--surface-content));
--surface-overlay: #1a1e21;
--primary-bg: color-mix(in srgb, var(--primary-color) 15%, var(--surface-card));
--control-bg: color-mix(in srgb, #fff 6%, var(--surface-app));
--control-primary-bg: var(--primary-bg);
--control-bg-hover-mix: 6%;
--control-border-mix: 12%;
--control-border-hover-mix: 18%;
--control-primary-bg-hover-mix: 12%;
--control-primary-border-mix: 25%;
--control-primary-border-hover-mix: 45%;
--control-focus-mix: 50%;
--control-bg-hover: color-mix(in srgb, #fff var(--control-bg-hover-mix), var(--control-bg));
--control-border: color-mix(in srgb, #fff var(--control-border-mix), var(--control-bg));
--control-border-hover: color-mix(in srgb, #fff var(--control-border-hover-mix), var(--control-bg));
--control-primary-bg-hover: color-mix(in srgb, var(--primary-color) var(--control-primary-bg-hover-mix), var(--control-primary-bg));
--control-primary-border: color-mix(in srgb, var(--primary-color) var(--control-primary-border-mix), var(--control-primary-bg));
--control-primary-border-hover: color-mix(in srgb, var(--primary-color) var(--control-primary-border-hover-mix), var(--control-primary-bg));
--control-focus-border: color-mix(in srgb, var(--primary-color) var(--control-focus-mix), var(--control-bg));
--control-focus-ring-color: color-mix(in srgb, var(--primary-color) var(--control-focus-mix), transparent);
--control-height: 2.625rem;
--control-height-sm: 2.25rem;
--control-padding-x: 0.75rem;
--control-padding-x-sm: 0.875rem;
--control-icon-size: 1rem;
--control-icon-size-sm: 0.875rem;
--control-gap: 0.5rem;
--control-radius: var(--radius-md);
--control-disabled-opacity: 0.5;
/* Borders */
--border-subtle: #34393e;
--border-strong: #464f56;
@@ -128,7 +162,7 @@
* Existing app styles still use these names. Prefer the canonical semantic
* tokens above for new native layout and page CSS.
*/
--ground-background: var(--app-background);
--ground-background: var(--surface-app);
--overlay-background: var(--surface-overlay);
--card-background: var(--surface-card);
--content-background: var(--surface-content);
+27
View File
@@ -9,6 +9,33 @@
display: none;
}
.surface-app,
.surface-page,
.surface-card {
--control-bg-hover: color-mix(in srgb, #fff var(--control-bg-hover-mix), var(--control-bg));
--control-border: color-mix(in srgb, #fff var(--control-border-mix), var(--control-bg));
--control-border-hover: color-mix(in srgb, #fff var(--control-border-hover-mix), var(--control-bg));
--control-focus-border: color-mix(in srgb, var(--primary-color) var(--control-focus-mix), var(--control-bg));
}
.surface-app {
--control-bg: color-mix(in srgb, #fff 6%, var(--surface-app));
background: var(--surface-app);
}
.surface-page {
--control-bg: color-mix(in srgb, #fff 6%, var(--surface-page));
background: var(--surface-page);
}
.surface-card {
--control-bg: color-mix(in srgb, #fff 6%, var(--surface-card));
background: var(--surface-card);
}
.gradient-divider {
flex-shrink: 0;
height: 1px;