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

discoverfinancial/a11y-theme-builder#167: fix color theme icon so tha… #373

Merged
merged 1 commit into from
May 9, 2023
Merged
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
24 changes: 16 additions & 8 deletions code/src/ui/src/components/CreateColorTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2023 Discover Financial Services
* Licensed under MIT License. See License.txt in the project root for license information
*/
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { Button } from '@mui/material';
import { ColorTheme, ColorThemes, Event, EventType, Shade } from 'a11y-theme-builder-sdk';
import { ColorSelect } from './ColorSelect';
Expand All @@ -23,11 +23,15 @@ interface Props {

export const CreateColorTheme: React.FC<Props> = ({atom, handleDefaultThemeInitialized}) => {

const defaultIconShade = Shade.fromHex("#ffffff");

const [_colorTheme, _setColorTheme] = useState<ColorTheme>();
const [_themeInitialized, _setThemeInitialized] = useState<boolean>(false);
const [_iconColor, _setIconColor] = useState<Shade>(Shade.fromHex("#ffffff"));
const [_iconColor, _setIconColor] = useState<Shade>(defaultIconShade);
const [_openConfirmation, _setOpenConfirmation] = useState<boolean>(false);

const colorIconRef = useRef<HTMLDivElement>(null);

useEffect(() => {
// creating a color theme should not work if the designSystem isn't
// able to accept new color themes
Expand Down Expand Up @@ -58,17 +62,21 @@ export const CreateColorTheme: React.FC<Props> = ({atom, handleDefaultThemeIniti
});
}

let newShade = colorTheme.icon.getValue();
if (newShade) {
_setIconColor(newShade);
}
colorTheme.icon.setListener("ColorThemeAtom-iconColor",
function (event: Event) {
if (event.type == EventType.ValueChanged) {
console.log(`Notified of default color theme icon color value changing, event: ${event}`);
newShade = colorTheme?.icon.getValue();
const newShade = colorTheme?.icon.getValue();
const iconSampleDiv = colorIconRef.current;
if (!iconSampleDiv) {
throw new Error("color icon sample missing DOM information");
}
if (newShade) {
_setIconColor(newShade);
iconSampleDiv.style.display = '';
} else {
_setIconColor(defaultIconShade);
iconSampleDiv.style.display = 'none';
}
}
}
Expand Down Expand Up @@ -154,7 +162,7 @@ export const CreateColorTheme: React.FC<Props> = ({atom, handleDefaultThemeIniti
<ColorSelect value={_colorTheme.icon} label="Color:"></ColorSelect>
<div className="input-col default-col">
<div className="caption">Sample Icon</div>
<div className="default-icon" id="themeIcon-sample">
<div className="default-icon" id="themeIcon-sample" ref={colorIconRef} style={{display: 'none'}}>
<div className="icon-body">
<svg width="24" height="24" viewBox="0 0 24 24" fill={_iconColor.getHexOrRGBA()} xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_775_36558)">
Expand Down