Skip to content
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

chore: oppdater dokumentasjon #2503

Merged
merged 1 commit into from
Jan 29, 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
9 changes: 9 additions & 0 deletions .storybook/colors.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.ffe-color-table {
td {
&:first-child {
width: auto;
}
width: 100px;
}
border-collapse: collapse;
}
1 change: 1 addition & 0 deletions .storybook/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@
@import '../packages/ffe-tables/less/tables';
@import '../packages/ffe-tabs/less/tabs';
@import '../packages/ffe-chips/less/chip';
@import './colors';
3 changes: 2 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StorybookConfig } from '@storybook/react-vite';
import { createRequire } from 'module';
import { dirname, join } from 'path';
const require = createRequire(import.meta.url);
import { join, dirname } from 'path';

/**
* This function is used to resolve the absolute path of a package.
Expand All @@ -13,6 +13,7 @@ function getAbsolutePath(value: string): any {

const config: StorybookConfig = {
stories: [
'../packages/ffe-core/documentation/Index.mdx',
'../packages/**/*.@(mdx)',
'../packages/**/*.stories.@(js|jsx|mjs|ts|tsx)',
],
Expand Down
1 change: 1 addition & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const preview: Preview = {
options: {
storySort: {
method: 'alphabetical',
order: ['Introduksjon', 'Design', 'Komponenter', 'Sider'],
},
},
},
Expand Down
7 changes: 7 additions & 0 deletions packages/ffe-core/documentation/AccentPage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Canvas, Meta } from '@storybook/blocks';

import * as AccentPageStories from './AccentPage.stories.tsx';

<Meta title="Sider/Accent" />

<Canvas of={AccentPageStories.Standard} />
35 changes: 35 additions & 0 deletions packages/ffe-core/documentation/AccentPage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { PrimaryButton } from '@sb1/ffe-buttons-react';
import { Heading1 } from '@sb1/ffe-core-react';
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';

const meta: Meta = {
title: 'Pages/Accent',
};
export default meta;

type Story = StoryObj;

export const Standard: Story = {
render: () => (
<div>
<div>
<Heading1>Test</Heading1>
<PrimaryButton>Knapp</PrimaryButton>
</div>
<div
className="ffe-accent-mode"
style={{
backgroundColor: 'var(--ffe-color-background-default)',
}}
>
<Heading1>Test</Heading1>
<PrimaryButton>Knapp</PrimaryButton>
</div>
<div>
<Heading1>Test</Heading1>
<PrimaryButton>Knapp</PrimaryButton>
</div>
</div>
),
};
60 changes: 60 additions & 0 deletions packages/ffe-core/documentation/Colors.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Meta } from '@storybook/blocks';
import { colors } from '../gen-src/semantic-color-names.json';

<Meta title="Design/Farger" />

# Farger

I designsystemet bruker vi semantiske farger. Det vil si at vi bruker farger med navn som
`--ffe-color-background-default` i stedet for fargekoder som `#000000`. Ved å bruke slike navn
kan vi variere hvilke farge som vises på tvers av appen. Vi støtter 4 moduser i dag:

- Light - default
- Light accent - for å fremheve elementer
- Dark - for mørk modus
- Dark accent - for å fremheve elementer i mørk modus

Dark mode aktiveres automatisk basert på brukerens systeminnstillinger.
Accent mode aktiveres med å legge klassen `ffe-accent-mode` på elementet eller på
containeren til elementet.

Bruken av accent er der en har en blokk på side med en annen bakgrunnsfarge enn resten.

Se eksempelet [på en slik side med en accent section]() WIP


## Liste over de semantiske fargene


<table class="ffe-color-table">
<thead>
<tr>
<th>Farge navn</th>
<th>Light</th>
<th>Light accent</th>
<th>Dark</th>
<th>Dark accent</th>
</tr>
</thead>
<tbody>
{colors.map(color => (
<tr key={color}>
<td>{color}</td>
<td style={{ backgroundColor: `var(${color})` }}></td>
<td
class="ffe-accent-mode"
style={{ backgroundColor: `var(${color})` }}
></td>
<td
class="dark-mode"
style={{ backgroundColor: `var(${color})` }}
></td>
<td
class="dark-mode ffe-accent-color"
style={{ backgroundColor: `var(${color})` }}
></td>
</tr>
))}
</tbody>
</table>

6 changes: 6 additions & 0 deletions packages/ffe-core/documentation/Index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Meta } from '@storybook/blocks';
import { colors } from '../gen-src/semantic-color-names.json';

<Meta title="Introduksjon/Velkommen" />

# Velkommen til Sparebank 1 Designsystem
39 changes: 39 additions & 0 deletions packages/ffe-core/documentation/colors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
// import {colors} from '../gen-src/semantic-color-names.js;

export const ColorsComponent = () => {
const colors = ['derp'];
return (
<table>
<thead>
<tr>
<th>Farge navn</th>
<th>Light</th>
<th>Light accent</th>
<th>Dark</th>
<th>Dark accent</th>
</tr>
</thead>
<tbody>
{colors.map(color => (
<tr key={color}>
<td>{color}</td>
<td style={{ backgroundColor: `var(${color})` }}></td>
<td
class="ffe-accent-mode"
style={{ backgroundColor: `var(${color})` }}
></td>
<td
class="dark-mode"
style={{ backgroundColor: `var(${color})` }}
></td>
<td
class="dark-mode ffe-accent-color"
style={{ backgroundColor: `var(${color})` }}
></td>
</tr>
))}
</tbody>
</table>
);
};
10 changes: 7 additions & 3 deletions packages/ffe-core/scripts/generate-semantic-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const writeToFile = require('./lib/writeToFile');

const usedPrimitive = {};
const usedSemantic = {};
const semanticColorNames = [];

const files = {
primitive: '01 Primitive.value.json',
Expand Down Expand Up @@ -46,6 +47,7 @@ const convertPrimitivesJsonToCss = jsonFile => {
const convertContextJsonToCss = jsonFile => {
const jsonContent = JSON.parse(fs.readFileSync(jsonFile, 'utf8'));
const cssLines = [];
const saveColors = semanticColorNames.length === 0;

const processColorTokens = (obj, prefix = '') => {
for (const [key, value] of Object.entries(obj)) {
Expand All @@ -64,6 +66,7 @@ const convertContextJsonToCss = jsonFile => {
: value.$value;
cssLines.push(`${cssVarName}: ${cssVarValue};`);
usedSemantic[cssVarValue] = true;
if (saveColors) semanticColorNames.push(cssVarName);
} else if (typeof value === 'object') {
processColorTokens(value, `${prefix}${key}-`);
}
Expand All @@ -80,7 +83,6 @@ const convertContextJsonToCss = jsonFile => {
const convertSemanticJsonToCss = (
jsonFile,
contextJsonFile,
contextAccentJsonFile,
isStorybook = false,
) => {
const jsonContent = JSON.parse(fs.readFileSync(jsonFile, 'utf8'));
Expand Down Expand Up @@ -141,16 +143,18 @@ function generateSemanticColors() {
cssContent += `\n\n// Context accent \n.ffe-accent-mode {\n${convertContextJsonToCss(filePath(files.contextAccent)).join('\n')}}\n`;
cssContent += `\n\n// Context \n:root,\n:host {\n${convertContextJsonToCss(filePath(files.context)).join('\n')}}\n`;
cssContent += `\n\n${convertSemanticJsonToCss(filePath(files.semanticLight))}`;
cssContent += `\n\n${convertSemanticJsonToCss(filePath(files.semanticDark), filePath(files.context), filePath(files.contextAccent))}`;
cssContent += `\n\n${convertSemanticJsonToCss(filePath(files.semanticDark), filePath(files.context))}`;
cssContent += `\n\n${convertPrimitivesJsonToCss(filePath(files.primitive))}`;

writeToFile('less/colors-semantic.less')(cssContent);
writeToFile('css/colors-semantic.css')(cssContent);
writeToFile('gen-src/semantic-color-names.json')(
JSON.stringify({ colors: semanticColorNames }),
);

const storybookCssContent = convertSemanticJsonToCss(
filePath(files.semanticDark),
filePath(files.context),
filePath(files.contextAccent),
true,
);
writeToFile('less/colors-semantic-storybook.less')(storybookCssContent);
Expand Down
Loading