Skip to content

Commit

Permalink
preview storybook components
Browse files Browse the repository at this point in the history
  • Loading branch information
nikk15 committed Aug 3, 2023
1 parent fd7dae4 commit ff7706d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@babel/preset-env": "^7.18.9",
"@babel/preset-react": "^7.18.6",
"@babel/register": "^7.18.9",
"@svgr/webpack": "^6.3.1",
"babel-loader": "^8.2.5",
"babel-plugin-react-intl": "^3.0.1",
"babel-plugin-transform-react-jsx-img-import": "^0.1.4",
Expand Down
32 changes: 29 additions & 3 deletions admin/src/react-components/ThemeBuilder/ThemeBuilder.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useMemo, useRef, useState} from 'react';
import React, { useEffect, useMemo, useRef, useState} from 'react';
// import theme from "../../utils/sample-theme";
import {Button, Input, Notification, NotificationInterfaceT, Select} from '@mozilla/lilypad-ui'
import { NewNotificationT } from '@mozilla/lilypad-ui';
import { CategoryE } from '@mozilla/lilypad-ui';
import { NotificationTypesE } from '@mozilla/lilypad-ui';
import { NotificationLocationE } from '@mozilla/lilypad-ui';
import {Base} from 'hubs/src/react-components/modal/Modal.stories'
import {RoomToolbar} from 'hubs/src/react-components/input/ToolbarButton.stories'

const success: NewNotificationT = {
title: "",
Expand All @@ -19,7 +21,6 @@ const error: NewNotificationT = {...success, type: NotificationTypesE.ERROR, des
const ThemeBuilder = ({config, onGlobalChange, onSave, path, setState, disableSave}) => {
const [themes, setThemes] =useState(JSON.parse(config?.hubs?.theme?.themes))
const [selectedTheme, setSelectedTheme] = useState(themes.find(theme => !!theme?.default))
const [showCrumb, setShowCrumb] = useState(false);
const formattedThemes = useMemo(() => themes.map(theme => ({title: theme.name, value: theme.id})), [themes, config]);
const notificationRef = useRef<NotificationInterfaceT>();

Expand Down Expand Up @@ -91,15 +92,38 @@ const ThemeBuilder = ({config, onGlobalChange, onSave, path, setState, disableSa
setSelectedTheme(newTheme)
}

useEffect(() => {
const variables = [];
console.log(selectedTheme)
for (const key in selectedTheme.variables) {
if (!Object.prototype.hasOwnProperty.call(selectedTheme.variables, key)) continue;
variables.push(`--${key}: ${selectedTheme.variables[key]};`);
}

const styleTag = document.createElement("style");

styleTag.innerHTML = `:root {
${variables.join("\n")}
}`;

document.head.appendChild(styleTag);

return () => {
document.head.removeChild(styleTag);
};
}, [selectedTheme]);

// edit name and validate no duplicates
// add new theme
// duplicate theme
// generate id from theme name?
// copy json
// delete theme
// preview components

// import theme from json - validate and populate missing variables
// import theme from web url?? - validate and populate missing variables
// select from github themes
// delete theme
// populate with defaults
// calculate darkness or lightness from states

Expand All @@ -118,6 +142,8 @@ const ThemeBuilder = ({config, onGlobalChange, onSave, path, setState, disableSa
<Button type="submit" text="Submit" label="Submit" disabled={disableSave}/>
</form>
<Notification ref={notificationRef} />
<RoomToolbar />
<Base />
</div>
)
}
Expand Down
30 changes: 30 additions & 0 deletions admin/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,36 @@ module.exports = (env, argv) => {
return /node_modules/.test(modulePath) && !/node_modules\/hubs/.test(modulePath);
}
},
{
test: /\.svg$/,
include: [path.resolve(__dirname, "node_modules", "hubs", "src", "react-components")],
use: [
{
loader: "@svgr/webpack",
options: {
titleProp: true,
replaceAttrValues: { "#000": "currentColor" },
exportType: "named",
svgo: true,
svgoConfig: {
plugins: [
{
name: "preset-default",
params: {
overrides: {
removeViewBox: false,
mergePaths: false,
convertShapeToPath: false,
removeHiddenElems: false
}
}
}
]
}
}
}
]
},
// TODO worker-loader has been deprecated, but we need "inline" support which is not available yet
// ideally instead of inlining workers we should serve them off the root domain instead of CDN.
{
Expand Down

0 comments on commit ff7706d

Please sign in to comment.