Skip to content

Initial darkside support #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-actors-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nais/ds-svelte-community": patch
---

Preview darkside
1 change: 1 addition & 0 deletions packages/ds-svelte-community/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ vite.config.ts.timestamp-*
/storybook-static
/src/testlib/*.d.ts
!/src/testlib/ambient.d.ts
.vscode
2 changes: 1 addition & 1 deletion packages/ds-svelte-community/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body class="doc" data-sveltekit-preload-data="hover">
<body class="doc" data-sveltekit-preload-data="hover" style="background: var(--ax-bg-default)">
<div>%sveltekit.body%</div>
</body>
</html>
52 changes: 24 additions & 28 deletions packages/ds-svelte-community/src/doclib/Properties.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@
}

.title {
font-size: var(--a-font-size-medium);
font-weight: var(--a-font-weight-bold);
background: var(--a-surface-alt-1-subtle);
font-size: var(--ax-font-size-medium, var(--a-font-size-medium));
font-weight: var(--ax-font-weight-bold, var(--a-font-weight-bold));
background: var(--ax-bg-meta-purple-moderate, var(--a-surface-alt-1-subtle));
user-select: none;
vertical-align: middle;

&:hover {
background: var(--a-surface-alt-1-moderate);
background: var(--ax-bg-meta-purple-moderate-hover, var(--a-surface-alt-1-moderate));
cursor: pointer;
}
}
Expand All @@ -235,14 +235,14 @@
button {
background: none;
border: none;
color: var(--a-text-subtle);
color: var(--ax-text-neutral, var(--a-text-subtle));
font-size: 0.9rem;
padding: 0.5rem;
margin: 0;
cursor: pointer;

&:hover {
color: var(--a-text-default);
color: var(--ax-text-default, var(--a-text-default));
}
}

Expand Down Expand Up @@ -284,72 +284,68 @@
tbody {
tr {
td {
border-bottom: 1px solid var(--a-border-default);
border-bottom: 1px solid var(--ax-border-neutral-subtle, var(--a-border-default));

&:first-of-type {
border-left: 1px solid var(--a-border-default);
border-left: 1px solid var(--ax-border-neutral-subtle, var(--a-border-default));
}
&:last-of-type {
border-right: 1px solid var(--a-border-default);
border-right: 1px solid var(--ax-border-neutral-subtle, var(--a-border-default));
}
}

&:first-child td {
border-top: 1px solid var(--a-border-default);
border-top: 1px solid var(--ax-border-neutral-subtle, var(--a-border-default));

&:first-of-type {
border-left: 1px solid var(--a-border-default);
border-top-left-radius: var(--a-border-radius-medium);
border-left: 1px solid var(--ax-border-neutral-subtle, var(--a-border-default));
border-top-left-radius: var(--ax-border-radius-medium, var(--a-border-radius-medium));
}
&:last-of-type {
border-right: 1px solid var(--a-border-default);
border-top-right-radius: var(--a-border-radius-medium);
border-right: 1px solid var(--ax-border-neutral-subtle, var(--a-border-default));
border-top-right-radius: var(--ax-border-radius-medium, var(--a-border-radius-medium));
}
}

&:last-child td {
&:first-of-type {
border-bottom-left-radius: var(--a-border-radius-medium);
border-bottom-left-radius: var(--ax-border-radius-medium, var(--a-border-radius-medium));
}
&:last-of-type {
border-bottom-right-radius: var(--a-border-radius-medium);
border-bottom-right-radius: var(--ax-border-radius-medium, var(--a-border-radius-medium));
}
}
}
}

thead {
th {
color: var(--a-text-subtle);
color: var(--ax-text-neutral, var(--a-text-subtle));
text-align: left;
}
}

span.required {
color: var(--a-text-danger);
}

.tags {
margin-top: 0.5rem;

span {
border: 1px solid var(--a-border-default);
border-radius: var(--a-border-radius-medium);
border: 1px solid var(--ax-border-neutral-subtle, var(--a-border-default));
border-radius: var(--ax-border-radius-medium, var(--a-border-radius-medium));
padding: 0.1rem 0.2rem;
font-size: 0.8rem;
font-size: var(--ax-font-size-small, var(--a-font-size-small));

&:not(:first-child) {
margin-left: 0.5rem;
}

&.required {
color: var(--a-text-danger);
border-color: var(--a-text-danger);
color: var(--ax-text-danger, var(--a-text-danger));
border-color: var(--ax-border-danger-subtle, var(--a-text-danger));
}

&.bindable {
color: var(--a-blue-700);
border-color: var(--a-blue-700);
color: var(--ax-text-info, var(--a-blue-700));
border-color: var(--ax-border-info, var(--a-blue-700));
}
}
}
Expand Down
30 changes: 17 additions & 13 deletions packages/ds-svelte-community/src/doclib/Renderer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@

<style>
.preview {
background-color: var(--a-surface-default);
border: 1px solid var(--a-border-default);
border-radius: var(--a-border-radius-medium);
background-color: var(--ax-bg-default, var(--a-surface-default));
border: 1px solid var(--ax-border-default, var(--a-border-default));
border-radius: var(--ax-border-radius-medium, var(--a-border-radius-medium));
min-height: 250px;
position: relative;

Expand All @@ -141,13 +141,16 @@
}

.code-preview {
font-size: var(--a-font-size-small);
font-size: var(--ax-font-size-small, var(--a-font-size-small));
position: relative;

.copy-code {
--ac-copybutton-neutral-text: var(--a-text-on-inverted);
--ac-copybutton-neutral-hover-text: var(--a-surface-alt-1-subtle);
--ac-copybutton-neutral-active-text: var(--a-surface-alt-1-moderate);
--ac-copybutton-neutral-text: var(--ax-text-default, var(--a-text-on-inverted));
--ac-copybutton-neutral-hover-text: var(--ax-text-meta-purple, var(--a-surface-alt-1-subtle));
--ac-copybutton-neutral-active-text: var(
--ax-text-meta-purple-strong,
var(--a-surface-alt-1-moderate)
);
display: none;

position: absolute;
Expand All @@ -161,24 +164,25 @@

& :global(pre) {
margin-top: 0;
border-bottom-left-radius: var(--a-border-radius-medium);
border-bottom-right-radius: var(--a-border-radius-medium);
border-bottom-left-radius: var(--ax-border-radius-medium, var(--a-border-radius-medium));
border-bottom-right-radius: var(--ax-border-radius-medium, var(--a-border-radius-medium));
}
}

.toggleCode {
position: absolute;
bottom: -1px;
right: -1px;
font-size: var(--a-font-size-small);
border: 1px solid var(--a-border-default);
font-size: var(--ax-font-size-small, var(--a-font-size-small));
border: 1px solid var(--ax-border-default, var(--a-border-default));
border-radius: 0;
border-top-left-radius: var(--a-border-radius-medium);
border-top-left-radius: var(--ax-border-radius-medium, var(--a-border-radius-medium));
padding: 0.2rem 0.5rem;
cursor: pointer;
background: var(--ax-bg-default);

&:hover {
background-color: var(--a-surface-alt-1-subtle);
background-color: var(--ax-bg-meta-purple-moderate-hover, var(--a-surface-alt-1-subtle));
}
}
</style>
4 changes: 2 additions & 2 deletions packages/ds-svelte-community/src/doclib/styles.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@tailwind utilities;

code {
background: var(--a-surface-alt-1-subtle);
border-radius: var(--a-border-radius-small);
background: var(--ax-bg-meta-purple-moderate, var(--a-surface-alt-1-subtle));
border-radius: var(--ax-border-radius-small, var(--a-border-radius-small));
padding: 0.1rem 0.3rem;
font-size: 0.7rem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Read more about this component in the [Aksel documentation](https://aksel.nav.no
<span class="navds-switch__track">
<span class="navds-switch__thumb">
{#if loading}
<Loader size="xsmall" aria-live="polite" />
<Loader size="xsmall" aria-live="polite" variant={checked ? "interaction" : "inverted"} />
{/if}
<SelectedIcon />
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
)}
class:navds-tabs__tab--icon-only={icon && !children}
class:unstyled={as === "a"}
data-state={ctx.value == value ? "active" : "inactive"}
type="button"
role="tab"
aria-controls={ctx.idFor("panel", value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Read more about this component in the [Aksel documentation](https://aksel.nav.no
id="r7"
class={classes(restProps, "navds-tooltip", "navds-detail", "navds-detail--small")}
data-side={placement}
data-state={open ? "open" : "closed"}
style="position: absolute; visibility: visible; {tooltipStyles}"
bind:clientWidth={tooltipWidth}
bind:clientHeight={tooltipHeight}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ describe("Bleed", () => {
await bunmatch(render(Bleed, props), ReactBleed, {
props,
children: [React.createElement("span", {}, "Bleed body")],
opts: {
alterAttrValue(name, value) {
// TODO: This is to support darkside styles
if (name === "style") {
const reg = /--__ax[^;]+;/g;
return value.replaceAll(reg, "");
}
return value;
},
},
}),
).toBeTrue();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ describe("Box", () => {
await bunmatch(render(Box, props), ReactBox, {
props,
children: [React.createElement("span", {}, "Box body")],
opts: {
alterAttrValue(name, value) {
// TODO: This is to support darkside styles
if (name === "style") {
const reg = /--__ax[^;]+;/g;
return value.replaceAll(reg, "");
}
return value;
},
},
}),
).toBeTrue();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ describe("HGrid", () => {
React.createElement("div", { key: "1" }),
React.createElement("div", { key: "2" }),
],
opts: {
alterAttrValue(name, value) {
// TODO: This is to support darkside styles
if (name === "style") {
const reg = /--__ax[^;]+;/g;
return value.replaceAll(reg, "");
}
return value;
},
},
}),
).toBeTrue();
});
Expand Down
22 changes: 21 additions & 1 deletion packages/ds-svelte-community/src/lib/components/utils/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const translateExceptionToCSS = (exception: string) => {
};

const translateTokenStringToCSS = (
domain: "a" | "ax",
componentProp: string,
tokenString: string,
tokenSubgroup: string,
Expand All @@ -46,7 +47,7 @@ const translateTokenStringToCSS = (
return `calc((100vw - ${width}%)/-2)`;
}

let output = `var(--a-${tokenSubgroup}-${x})`;
let output = `var(--${domain}-${tokenSubgroup}-${x})`;
if (tokenExceptions.includes(x)) {
output = translateExceptionToCSS(x);
}
Expand Down Expand Up @@ -76,6 +77,15 @@ export function getResponsiveProps<T extends string>(
if (typeof responsiveProp === "string") {
return {
[`--__ac-${componentName}-${componentProp}-xs`]: translateTokenStringToCSS(
"a",
componentProp,
responsiveProp,
tokenSubgroup,
tokenExceptions,
invert,
),
[`--__axc-${componentName}-${componentProp}-xs`]: translateTokenStringToCSS(
"ax",
componentProp,
responsiveProp,
tokenSubgroup,
Expand All @@ -89,6 +99,16 @@ export function getResponsiveProps<T extends string>(
Object.entries(responsiveProp).forEach(([breakpointAlias, aliasOrScale]) => {
styleProps[`--__ac-${componentName}-${componentProp}-${breakpointAlias}`] =
translateTokenStringToCSS(
"a",
componentProp,
aliasOrScale,
tokenSubgroup,
tokenExceptions,
invert,
);
styleProps[`--__axc-${componentName}-${componentProp}-${breakpointAlias}`] =
translateTokenStringToCSS(
"ax",
componentProp,
aliasOrScale,
tokenSubgroup,
Expand Down
Loading
Loading