-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
313 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Popover } from '@headlessui/react'; | ||
import { InputField } from 'app/V2/Components/Forms'; | ||
|
||
type ColorPickerProps = { | ||
name: string; | ||
onChange?: (color: string) => void; | ||
value?: string; | ||
className?: string; | ||
hasErrors?: boolean; | ||
}; | ||
|
||
const defaultColors = [ | ||
'#C03B22', | ||
'#D9534F', | ||
'#E91E63', | ||
'#A03AB1', | ||
'#6F46B8', | ||
'#3F51B5', | ||
'#2196F3', | ||
'#37BDCF', | ||
'#359990', | ||
'#5CB85C', | ||
'#8BC34A', | ||
'#CDDC39', | ||
'#CCBC2F', | ||
'#F0AD4E', | ||
'#EC9920', | ||
'#E46841', | ||
'#795548', | ||
'#9E9E9E', | ||
'#607D8B', | ||
]; | ||
|
||
const ColorPicker = ({ | ||
name, | ||
className, | ||
onChange, | ||
hasErrors, | ||
value = defaultColors[0], | ||
}: ColorPickerProps) => { | ||
const [localValue, setLocalValue] = useState(value); | ||
|
||
useEffect(() => { | ||
setLocalValue(value); | ||
}, [value]); | ||
|
||
const changeColor = (color: string) => { | ||
setLocalValue(color); | ||
if (onChange) { | ||
onChange(color); | ||
} | ||
}; | ||
|
||
const dynamicStyles = hasErrors ? 'border-error-300' : 'border-gray-100'; | ||
|
||
return ( | ||
<div className={`${className}`}> | ||
<Popover className=""> | ||
<Popover.Button | ||
className={`w-[37px] h-[37px] border cursor-pointer rounded-lg ring-0 ${dynamicStyles}`} | ||
> | ||
<div | ||
data-testid="colorpicker-button" | ||
className="m-auto rounded-md w-7 h-7" | ||
style={{ backgroundColor: localValue }} | ||
/> | ||
</Popover.Button> | ||
<Popover.Panel | ||
as="div" | ||
className="flex flex-col gap-2 p-2 bg-white rounded-md shadow max-w-[188px] z-10 m-2" | ||
> | ||
<ul className="flex flex-wrap gap-2" data-testid="colorpicker-popover"> | ||
{defaultColors.map((color: string) => ( | ||
<li key={color}> | ||
<button | ||
type="button" | ||
className="w-full cursor-pointer" | ||
onClick={() => changeColor(color)} | ||
> | ||
<span className="sr-only">{color}</span> | ||
<div | ||
data-testid="colorpicker-button" | ||
className="m-auto rounded-sm w-7 h-7" | ||
style={{ backgroundColor: color }} | ||
/> | ||
</button> | ||
</li> | ||
))} | ||
</ul> | ||
<InputField | ||
id={name} | ||
type="text" | ||
name={name} | ||
value={localValue.slice(1)} | ||
preText="#" | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { | ||
changeColor(`#${e.target.value}`); | ||
}} | ||
className="w-full" | ||
hasErrors={hasErrors} | ||
/> | ||
</Popover.Panel> | ||
</Popover> | ||
</div> | ||
); | ||
}; | ||
|
||
export { ColorPicker }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,57 @@ | ||
import { createStore } from 'jotai'; | ||
import { isClient } from 'app/utils'; | ||
import { store } from 'app/store'; | ||
import { ClientSettings, ClientThesaurus, ClientUserSchema } from 'app/apiResponseTypes'; | ||
import { ClientTemplateSchema } from 'app/istore'; | ||
import { globalMatomoAtom } from './globalMatomoAtom'; | ||
import { relationshipTypesAtom } from './relationshipTypes'; | ||
import { settingsAtom } from './settingsAtom'; | ||
import { templatesAtom } from './templatesAtom'; | ||
import { translationsAtom } from './translationsAtom'; | ||
import { userAtom } from './userAtom'; | ||
import { thesauriAtom } from './thesauriAtom'; | ||
|
||
type AtomStoreData = { | ||
globalMatomo?: { url: string; id: string }; | ||
locale?: string; | ||
settings?: ClientSettings; | ||
thesauri?: ClientThesaurus[]; | ||
templates?: ClientTemplateSchema[]; | ||
user?: ClientUserSchema; | ||
}; | ||
|
||
declare global { | ||
interface Window { | ||
__atomStoreData__?: { globalMatomo: { url: string; id: string } | undefined }; | ||
__atomStoreData__?: AtomStoreData; | ||
} | ||
} | ||
|
||
const atomStore = createStore(); | ||
|
||
if (isClient && window.__atomStoreData__?.globalMatomo) { | ||
atomStore.set(globalMatomoAtom, { ...window.__atomStoreData__?.globalMatomo }); | ||
if (isClient && window.__atomStoreData__) { | ||
const { globalMatomo, locale, settings, thesauri, templates, user } = window.__atomStoreData__; | ||
|
||
if (globalMatomo) atomStore.set(globalMatomoAtom, { ...globalMatomo }); | ||
if (settings) atomStore.set(settingsAtom, settings); | ||
if (thesauri) atomStore.set(thesauriAtom, thesauri); | ||
if (templates) atomStore.set(templatesAtom, templates); | ||
atomStore.set(userAtom, user); | ||
atomStore.set(translationsAtom, { locale: locale || 'en' }); | ||
|
||
//sync deprecated redux store | ||
atomStore.sub(settingsAtom, () => { | ||
const value = atomStore.get(settingsAtom); | ||
store?.dispatch({ type: 'settings/collection/SET', value }); | ||
}); | ||
atomStore.sub(templatesAtom, () => { | ||
const value = atomStore.get(templatesAtom); | ||
store?.dispatch({ type: 'templates/SET', value }); | ||
}); | ||
atomStore.sub(relationshipTypesAtom, () => { | ||
const value = atomStore.get(relationshipTypesAtom); | ||
store?.dispatch({ type: 'relationTypes/SET', value }); | ||
}); | ||
} | ||
|
||
export type { AtomStoreData }; | ||
export { atomStore }; |
Oops, something went wrong.