Add new concept for CSS variables within styles

This commit is contained in:
Andrew Kingston 2025-03-07 15:19:59 +00:00
parent d8a3258f33
commit ad6e8abc74
No known key found for this signature in database
5 changed files with 38 additions and 6 deletions

View File

@ -2,6 +2,7 @@
import StyleSection from "./StyleSection.svelte" import StyleSection from "./StyleSection.svelte"
import * as ComponentStyles from "./componentStyles" import * as ComponentStyles from "./componentStyles"
import ComponentSettingsSection from "./ComponentSettingsSection.svelte" import ComponentSettingsSection from "./ComponentSettingsSection.svelte"
import ColorPicker from "@/components/design/settings/controls/ColorPicker.svelte"
export let componentDefinition export let componentDefinition
export let componentInstance export let componentInstance
@ -18,6 +19,19 @@
styles.push(ComponentStyles[style]) styles.push(ComponentStyles[style])
} }
}) })
// Add section for CSS variables if present
if (def?.cssVariables?.length) {
styles.push({
label: "Customization",
settings: def.cssVariables.map(variable => ({
label: variable.label,
key: variable.variable,
control: ColorPicker,
})),
})
}
return styles return styles
} }

View File

@ -7584,6 +7584,15 @@
"name": "Table", "name": "Table",
"icon": "Table", "icon": "Table",
"styles": ["size"], "styles": ["size"],
"cssVariables": [{
"label": "Header color",
"variable": "--custom-header-cell-background",
"type": "color"
}, {
"label": "Stripe color",
"variable": "--custom-stripe-cell-background",
"type": "color"
}],
"size": { "size": {
"width": 600, "width": 600,
"height": 400 "height": 400

View File

@ -434,7 +434,7 @@
.header-cell :global(.cell) { .header-cell :global(.cell) {
padding: 0 var(--cell-padding); padding: 0 var(--cell-padding);
gap: calc(2 * var(--cell-spacing)); gap: calc(2 * var(--cell-spacing));
background: var(--grid-background-alt); background: var(--header-cell-background);
} }
/* Icon colors */ /* Icon colors */

View File

@ -217,6 +217,10 @@
--accent-color: var(--primaryColor, var(--spectrum-global-color-blue-400)); --accent-color: var(--primaryColor, var(--spectrum-global-color-blue-400));
--grid-background: var(--spectrum-global-color-gray-50); --grid-background: var(--spectrum-global-color-gray-50);
--grid-background-alt: var(--spectrum-global-color-gray-100); --grid-background-alt: var(--spectrum-global-color-gray-100);
--header-cell-background: var(
--custom-header-cell-background,
var(--grid-background-alt)
);
--cell-background: var(--grid-background); --cell-background: var(--grid-background);
--cell-background-hover: var(--grid-background-alt); --cell-background-hover: var(--grid-background-alt);
--cell-background-alt: var(--cell-background); --cell-background-alt: var(--cell-background);
@ -246,7 +250,10 @@
cursor: grabbing !important; cursor: grabbing !important;
} }
.grid.stripe { .grid.stripe {
--cell-background-alt: var(--spectrum-global-color-gray-75); --cell-background-alt: var(
--custom-stripe-cell-background,
var(--spectrum-global-color-gray-75)
);
} }
/* Data layers */ /* Data layers */
@ -360,8 +367,10 @@
.grid.quiet :global(.sticky-column:before) { .grid.quiet :global(.sticky-column:before) {
display: none; display: none;
} }
.grid.quiet :global(.header), .grid.quiet:not(.stripe) {
.grid.quiet :global(.header .cell) { --header-cell-background: var(
background: var(--grid-background); --custom-header-cell-background,
var(--grid-background)
);
} }
</style> </style>

View File

@ -169,7 +169,7 @@
z-index: 1; z-index: 1;
} }
.header :global(.cell) { .header :global(.cell) {
background: var(--grid-background-alt); background: var(--header-cell-background);
} }
.header :global(.cell::before) { .header :global(.cell::before) {
display: none; display: none;