Skip to content
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/full-carpets-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@drivenets/vite-plugin-design-system': patch
---

Export fonts URLs
12 changes: 12 additions & 0 deletions packages/design-system/.storybook/create-font-links-html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { fontPreconnectURLs, fontStylesheetURLs } from '@drivenets/vite-plugin-design-system';

export function createFontLinksHtml() {
const preconnect = fontPreconnectURLs.map((href) => `<link rel="preconnect" href="${href}" crossorigin />`);

const stylesheets = fontStylesheetURLs.flatMap((href) => [
`<link rel="preload" as="style" href="${href}" />`,
`<link rel="stylesheet" href="${href}" />`,
]);

return [...preconnect, ...stylesheets].join('\n');
}
4 changes: 4 additions & 0 deletions packages/design-system/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import remarkGfm from 'remark-gfm';
// @ts-expect-error - See https://storybook.js.org/docs/faq#extensionless-imports-in-storybook-main-config
import { reactCompilerRolldownPlugin } from '../rolldown/react-compiler-rolldown-plugin.ts';

// @ts-expect-error - See https://storybook.js.org/docs/faq#extensionless-imports-in-storybook-main-config
import { createFontLinksHtml } from './create-font-links-html.ts';

const config: StorybookConfig = {
stories: ['../src/**/!(*.docs).mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
Expand All @@ -23,6 +26,7 @@ const config: StorybookConfig = {
'@storybook/addon-mcp',
],
framework: '@storybook/react-vite',
managerHead: (head = '') => `${head}\n${createFontLinksHtml()}`,
viteFinal: (viteConfig) => {
if (!Array.isArray(viteConfig.plugins)) {
viteConfig.plugins = [];
Expand Down
4 changes: 4 additions & 0 deletions packages/design-system/.storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { addons } from 'storybook/manager-api';
import { darkTheme } from './themes';

addons.setConfig({ theme: darkTheme });
4 changes: 4 additions & 0 deletions packages/design-system/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type { Preview } from '@storybook/react-vite';
import '../src/styles/styles.scss';
import { lightTheme } from './themes';

const preview: Preview = {
tags: ['autodocs'],
parameters: {
docs: {
theme: lightTheme,
},
options: {
storySort: {
order: [
Expand Down
16 changes: 16 additions & 0 deletions packages/design-system/.storybook/themes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { create as createTheme, type ThemeVarsPartial } from 'storybook/theming';

const fonts = {
fontBase: 'Roboto',
fontCode: 'Fira Mono',
} satisfies Omit<ThemeVarsPartial, 'base'>;

export const lightTheme = createTheme({
base: 'light',
...fonts,
});

export const darkTheme = createTheme({
base: 'dark',
...fonts,
});
22 changes: 11 additions & 11 deletions packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import type { Plugin } from 'vite';

export const fontPreconnectURLs = ['https://fonts.googleapis.com', 'https://fonts.gstatic.com'] as const;

export const fontStylesheetURLs = [
'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap',
'https://fonts.googleapis.com/css2?family=Fira+Mono:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap',
'https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20,400,0..1,0&display=block',
'https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20,400,0..1,0&display=block',
] as const;

export function vitePluginDesignSystem(): Plugin {
return {
name: 'vite-plugin-design-system',
transformIndexHtml(html) {
const stylesheets = [
'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap',
'https://fonts.googleapis.com/css2?family=Fira+Mono:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap',
'https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20,400,0..1,0&display=block',
'https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20,400,0..1,0&display=block',
];

const preconnect = ['https://fonts.googleapis.com', 'https://fonts.gstatic.com'];

return {
html,
tags: [
...preconnect.map((href) => ({
...fontPreconnectURLs.map((href) => ({
tag: 'link',
attrs: {
rel: 'preconnect',
Expand All @@ -26,7 +26,7 @@ export function vitePluginDesignSystem(): Plugin {
injectTo: 'head' as const,
})),

...stylesheets.flatMap((href) => [
...fontStylesheetURLs.flatMap((href) => [
{
tag: 'link',
attrs: {
Expand Down
Loading