Skip to content

Commit

Permalink
refactor: add simple SVG file loader
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjavi committed Sep 3, 2023
1 parent cf6ecb8 commit cff5373
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/docs/.storylite/config.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SLAddonPropsWithoutId, SLAppComponentProps } from '@storylite/storylite'
import { BoxIcon, GithubIcon, ZapIcon } from 'lucide-react'

const config: SLAppComponentProps = {
const config: Partial<SLAppComponentProps> = {
title: ' ⚡️ StoryLite',
defaultStory: 'index-default',
useIframeStyles: false,
Expand Down
29 changes: 28 additions & 1 deletion packages/docs/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions packages/docs/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ export default {
renderFrame: 'root',
component: () => (
<div>
<img src="logo.svg" alt="StoryLite Logo" />
<h1>⚡️ StoryLite,</h1>
<h3>a lightweight alternative to StoryBook.</h3>
<img src="logo.svg" width={64} height={64} alt="StoryLite Logo" />
<h1>StoryLite, a lightweight alternative to StoryBook.</h1>
<p>
<b>StoryLite</b> is a modern and lightweight toolkit for crafting and managing design
systems and components with ease. Inspired by the popular StoryBook UI and powered by
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/react/.storylite/config.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SLAddonPropsWithoutId, SLAppComponentProps } from '@storylite/storylite'

const config: SLAppComponentProps = {
const config: Partial<SLAppComponentProps> = {
title: ' ⚡️ StoryLite React',
defaultStory: 'index-default',
useIframeStyles: false,
Expand Down
29 changes: 28 additions & 1 deletion packages/examples/react/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions packages/storylite/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/storylite/declaration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.svg' {
const content: string
export default content
}
1 change: 0 additions & 1 deletion packages/storylite/public/vite.svg

This file was deleted.

14 changes: 14 additions & 0 deletions packages/storylite/src/app/stores/DefaultTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import logo from '@/assets/logo.svg'
import { InlineHtml } from '@/components/InlineHtml'

export function DefaultTitle(): JSX.Element {
return (
<>
<InlineHtml style={{ width: '24px', height: '24px' }}>{logo}</InlineHtml> StoryLite
</>
)
}

export function getDefaultTitle(): JSX.Element {
return <DefaultTitle />
}
3 changes: 2 additions & 1 deletion packages/storylite/src/app/stores/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@/components/addons/getToolbarAddons'
import { SLAddonsMap, SLParameters, SLUserDefinedAddons, StoryMap, StoryModuleMap } from '@/types'

import { getDefaultTitle } from './DefaultTitle'
import { StoryLiteActions, StoryLiteState } from './global.types'

const builtinAddons: SLAddonsMap = new Map(
Expand All @@ -21,7 +22,7 @@ const defaultState: StoryLiteState = {
standalone: false,
},
config: {
title: 'Story Lite',
title: getDefaultTitle(),
defaultStory: 'index',
iframeProps: {},
useIframeStyles: true,
Expand Down
16 changes: 16 additions & 0 deletions packages/storylite/src/components/InlineHtml.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HTMLProps } from 'react'
import { cn } from '@r1stack/cn'

type InlineHtmlProps = {
children: string
} & HTMLProps<HTMLSpanElement>

export function InlineHtml({ children, className, ...rest }: InlineHtmlProps): JSX.Element {
return (
<span
className={cn('storylite-inlinehtml', className)}
dangerouslySetInnerHTML={{ __html: children }}
{...rest}
/>
)
}
5 changes: 5 additions & 0 deletions packages/storylite/src/styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@
:where(.storylite-iframe:not(.storylite-iframe--default-styles)) {
background: transparent;
}

.storylite-inlinehtml {
display: inline-block;
vertical-align: middle;
}
3 changes: 2 additions & 1 deletion packages/storylite/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
"noEmit": true,
"baseUrl": ".",
"paths": {
"@/assets/*": ["./assets/*"],
"@/": ["./src/"],
"@/*": ["./src/*"]
},
"types": ["node", "jest", "react", "react-dom"]
},
"include": ["src", "*.ts"]
"include": ["src", "assets", "*.ts"]
}
3 changes: 3 additions & 0 deletions packages/storylite/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export default defineConfig([
types: ['node'],
},
},
loader: {
'.svg': 'text',
},
sourcemap: true,
splitting: true,
minify: false,
Expand Down

0 comments on commit cff5373

Please sign in to comment.