Skip to content

Commit

Permalink
Merge pull request #5 from raulmelo/release/event-loop-persist-data
Browse files Browse the repository at this point in the history
hotfix: bug loop in persist data
  • Loading branch information
raulmelo authored Dec 2, 2023
2 parents ae95953 + fcac9cc commit 56ba441
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 474 deletions.
2 changes: 1 addition & 1 deletion .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Preview } from "@storybook/react";
import Themes from './themes.json'
import Themes from '../EXAMPLES_THEMES.json';

const preview: Preview = {
parameters: {
Expand Down
65 changes: 0 additions & 65 deletions .storybook/themes.json

This file was deleted.

65 changes: 65 additions & 0 deletions EXAMPLES_THEMES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[
{
"name": "Theme one",
"tokens": {
"--font-family": "Roboto, sans-serif",
"--primary": "#fcfc30",
"--primary-text": "#00A8FF",
"--primary-container": "#fcf130",
"--primary-light": "#fcfc30",
"--primary-dark": "#FFFFFF",
"--primary-hover": "#fae128",
"--secondary": "#465eff",
"--secondary-text": "#fff",
"--secondary-container": "#2f4af8",
"--secondary-light": "#465eff",
"--secondary-dark": "#465eff",
"--secondary-hover": "#465eff",
"--background": "#fcfc30",
"--background-gradient": "linear-gradient(to right, var(--secondary), var(--secondary-dark))",
"--text": "#000"
}
},
{
"name": "Theme Two",
"miniLogo": "https://javisperez.github.io/tailwindcolorshades/img/icons/favicon-16x16.png",
"tokens": {
"--primary": "#c8c615",
"--primary-text": "#faf9e8",
"--primary-container": "#b4b213",
"--primary-light": "#e9e8a1",
"--primary-dark": "#62610a",
"--primary-hover": "#969510",
"--secondary": "#8a59a7",
"--secondary-text": "#f3eef6",
"--secondary-container": "#7c5096",
"--secondary-light": "#d0bddc",
"--secondary-dark": "#533564",
"--secondary-hover": "#533564",
"--background": "#fcfc30",
"--background-gradient": "linear-gradient(to right, var(--secondary), var(--secondary-dark))",
"--text": "#000"
}
},
{
"name": "Theme Three",
"miniLogo": "https://www.gclaims.com.br/assets/images/favicon/favicon-16x16.png",
"tokens": {
"--primary": "#00a8ff",
"--primary-text": "#e6f6ff",
"--primary-container": "#007ebf",
"--primary-light": "#99dcff",
"--primary-dark": "#006599",
"--primary-hover": "#007ebf",
"--secondary": "#00c9a8",
"--secondary-text": "#e6faf6",
"--secondary-container": "#00c9a8",
"--secondary-light": "#4dd9c2",
"--secondary-dark": "#00977e",
"--secondary-hover": "#00b597",
"--background": "#fcfc30",
"--background-gradient": "linear-gradient(to right, var(--primary), var(--primary-dark))",
"--text": "#000"
}
}
]
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export const parameters = {
"miniLogo": "",
"tokens": {
## add all yours css variables here
"yours-primary": "#c8c615",
"yours-primary-text": "#faf9e8",
"yours-primary-container": "#b4b213",
"yours-primary-light": "#e9e8a1",
"yours-primary-dark": "#62610a",
"yours-primary-hover": "#969510"
"--yours-primary": "#c8c615",
"--yours-primary-text": "#faf9e8",
"--yours-primary-container": "#b4b213",
"--yours-primary-light": "#e9e8a1",
"--yours-primary-dark": "#62610a",
"--yours-primary-hover": "#969510"
## add all yours css variables here
}
},
Expand All @@ -84,12 +84,12 @@ export const parameters = {
"miniLogo": "https://javisperez.github.io/tailwindcolorshades/img/icons/favicon-16x16.png",
"tokens": {
## add all yours css variables here
"yours-primary": "#c8c615",
"yours-primary-text": "#faf9e8",
"yours-primary-container": "#b4b213",
"yours-primary-light": "#e9e8a1",
"yours-primary-dark": "#62610a",
"yours-primary-hover": "#969510"
"--yours-primary": "#c8c615",
"--yours-primary-text": "#faf9e8",
"--yours-primary-container": "#b4b213",
"--yours-primary-light": "#e9e8a1",
"--yours-primary-dark": "#62610a",
"--yours-primary-hover": "#969510"
## add all yours css variables here
}
},
Expand Down
36 changes: 0 additions & 36 deletions src/Panel.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions src/Tab.tsx

This file was deleted.

12 changes: 7 additions & 5 deletions src/Tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import { PARAM_KEY, TOOL_ID } from "./constants";
import { DropdownTool } from "./components/Dropdown";
import { ThemeTokensType, ThemeType } from "./utils/types";
import { DisplayToolState } from "./utils/actions";
import { GetDataStorage } from "./utils/persist";

export const Tool = memo(function MyAddonSelector() {
const [{ themeVariableCss }] = useGlobals();
const [ global, updateGlobals] = useGlobals();
const tokensCss = useParameter<ThemeTokensType>(PARAM_KEY)


useEffect( () => {
if(tokensCss && themeVariableCss) {
const themeSelected = tokensCss?.themes.filter((_theme: ThemeType) => _theme.name === themeVariableCss?.name)[0];
DisplayToolState('html', {isInDocs: false, themeVariableCss: themeVariableCss.name, themeSelected: themeSelected} )
if(tokensCss && global.themeVariableCss) {
const themeSelected = tokensCss?.themes.filter((_theme: ThemeType) => _theme.name === global.themeVariableCss?.name)[0];
DisplayToolState('html', {isInDocs: false, themeVariableCss: global.themeVariableCss.name, themeSelected: themeSelected} )
}
}, [themeVariableCss])
}, [global.themeVariableCss])

if (!tokensCss && !tokensCss?.themes?.length) {
return null
Expand Down
22 changes: 18 additions & 4 deletions src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MountedOptions, ValidatorArrayTheme } from "../utils";
import { OptionsThemeType, ThemeType } from "../utils/types";
import { ButtonItem, ItemSelected, ViewToolTip } from "./styles";
import { useGlobals } from "@storybook/manager-api";
import { GetDataStorage } from "src/utils/persist";

interface propsDropDown {
list: ThemeType[]
Expand All @@ -19,13 +20,21 @@ export const DropdownTool = memo( function myDropdownMemo(props: propsDropDown)
const [options, setOptions] = React.useState<OptionsThemeType[]>([]);

React.useEffect(() => {
const dataLocal: any = GetDataStorage();
if(dataLocal?.selected) {
updateGlobals({
...global,
themeVariableCss: dataLocal.selected
})
}
setListOptionsItem()
}, [])


const LabelState = React.useCallback(() => {
return <>
{!!themeVariableCss && !!themeVariableCss?.name ?
<ItemSelected shadow className={`button-` + PARAM_KEY}>
<ItemSelected shadow className={`button-` + PARAM_KEY + '-selected'}>
{!!themeVariableCss?.miniLogo &&
<img src={themeVariableCss.miniLogo} alt=""/>
}
Expand Down Expand Up @@ -74,10 +83,15 @@ export const DropdownTool = memo( function myDropdownMemo(props: propsDropDown)
return (
<ButtonItem
key={index}
className={
`button-` + PARAM_KEY
+ (themeVariableCss?.name === item.name ? ' selected' : '')
}
onClick={() => toggleMyTool(item)}

>
{item.type === 'icon' && <Icons icon="lightning" /> }
{item.type === 'image' && <img src={item.miniLogo} alt=""/> }
{item.type === 'icon' && <Icons icon="starhollow" /> }
{(item.type === 'image' && !!item.miniLogo) && <img src={item.miniLogo} alt=""/> }
{item.name}
</ButtonItem>
)
Expand All @@ -88,7 +102,7 @@ export const DropdownTool = memo( function myDropdownMemo(props: propsDropDown)

return (
<WithTooltip placement="top" trigger="click" tooltip={ () => ComponentItem() }>
{LabelState()}
<LabelState />
</WithTooltip>
);
});
Loading

0 comments on commit 56ba441

Please sign in to comment.