ThemeConfigurator düzenlemesi
This commit is contained in:
parent
0e1e83fc00
commit
8118404895
2 changed files with 23 additions and 19 deletions
|
|
@ -1,16 +1,16 @@
|
||||||
import { HiCheck } from 'react-icons/hi'
|
import { HiCheck } from 'react-icons/hi'
|
||||||
import { components } from 'react-select'
|
import { components } from 'react-select'
|
||||||
|
import classNames from 'classnames'
|
||||||
|
|
||||||
import { Select, toast } from '@/components/ui'
|
import { Select, toast } from '@/components/ui'
|
||||||
import { styleMapOptions } from '@/views/admin/listForm/edit/options'
|
import { styleMapOptions } from '@/views/admin/listForm/edit/options'
|
||||||
import Notification from '@/components/ui/Notification'
|
import Notification from '@/components/ui/Notification'
|
||||||
import { useLocalization } from '@/utils/hooks/useLocalization'
|
|
||||||
import { useStoreActions, useStoreState } from '@/store'
|
import { useStoreActions, useStoreState } from '@/store'
|
||||||
import { updateSettingValues } from '@/services/setting-ui.service'
|
import { updateSettingValues } from '@/services/setting-ui.service'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
const StyleSwitcher = ({ onStyleChange }: { onStyleChange?: () => void }) => {
|
const StyleSwitcher = ({ onStyleChange }: { onStyleChange?: () => void }) => {
|
||||||
const { translate } = useLocalization()
|
const menuItemHeight = 36
|
||||||
const { setMode, setStyle, setThemeColor, setThemeColorLevel, abpConfig } = useStoreActions(
|
const { setMode, setStyle, setThemeColor, setThemeColorLevel, abpConfig } = useStoreActions(
|
||||||
(actions) => ({
|
(actions) => ({
|
||||||
setMode: actions.theme.setMode,
|
setMode: actions.theme.setMode,
|
||||||
|
|
@ -20,7 +20,7 @@ const StyleSwitcher = ({ onStyleChange }: { onStyleChange?: () => void }) => {
|
||||||
abpConfig: actions.abpConfig.getConfig,
|
abpConfig: actions.abpConfig.getConfig,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
const { style, themeColor, primaryColorLevel } = useStoreState((state) => state.theme)
|
const { style } = useStoreState((state) => state.theme)
|
||||||
|
|
||||||
const onSetStyle = React.useCallback(
|
const onSetStyle = React.useCallback(
|
||||||
async (val: any) => {
|
async (val: any) => {
|
||||||
|
|
@ -44,17 +44,20 @@ const StyleSwitcher = ({ onStyleChange }: { onStyleChange?: () => void }) => {
|
||||||
abpConfig(false)
|
abpConfig(false)
|
||||||
if (onStyleChange) onStyleChange()
|
if (onStyleChange) onStyleChange()
|
||||||
},
|
},
|
||||||
[setStyle, setMode, abpConfig, translate, onStyleChange],
|
[setStyle, setMode, setThemeColor, setThemeColorLevel, abpConfig, onStyleChange],
|
||||||
)
|
)
|
||||||
|
|
||||||
// Custom Option
|
// Custom Option
|
||||||
const CustomSelectOption = ({ innerProps, label, data, isSelected }: any) => {
|
const CustomSelectOption = ({ innerProps, label, data, isSelected, isFocused }: any) => {
|
||||||
const { border, fill } = data.color
|
const { border, fill } = data.color
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`flex items-center justify-between p-2 cursor-pointer ${
|
className={classNames(
|
||||||
isSelected ? 'bg-gray-100 dark:bg-gray-500' : 'hover:bg-gray-50 dark:hover:bg-gray-600'
|
'select-option cursor-pointer',
|
||||||
}`}
|
isSelected && 'selected',
|
||||||
|
isFocused && 'focused',
|
||||||
|
)}
|
||||||
|
style={{ minHeight: menuItemHeight }}
|
||||||
{...innerProps}
|
{...innerProps}
|
||||||
>
|
>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
|
|
@ -81,7 +84,7 @@ const StyleSwitcher = ({ onStyleChange }: { onStyleChange?: () => void }) => {
|
||||||
// Custom Control
|
// Custom Control
|
||||||
const CustomControl = ({ children, ...props }: any) => {
|
const CustomControl = ({ children, ...props }: any) => {
|
||||||
const selected = props.getValue()[0]
|
const selected = props.getValue()[0]
|
||||||
const { border, fill } = selected?.color
|
const { border, fill } = selected?.color || { border: '#ccc', fill: '#fff' }
|
||||||
return (
|
return (
|
||||||
<components.Control {...props}>
|
<components.Control {...props}>
|
||||||
{selected ? (
|
{selected ? (
|
||||||
|
|
@ -108,15 +111,17 @@ const StyleSwitcher = ({ onStyleChange }: { onStyleChange?: () => void }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
value={styleMapOptions.find((o) => o.value === style)}
|
|
||||||
options={styleMapOptions}
|
|
||||||
onChange={(option: any) => {
|
|
||||||
onSetStyle(option)
|
|
||||||
}}
|
|
||||||
components={{
|
components={{
|
||||||
Option: CustomSelectOption,
|
Option: CustomSelectOption,
|
||||||
Control: CustomControl,
|
Control: CustomControl,
|
||||||
}}
|
}}
|
||||||
|
isSearchable={true}
|
||||||
|
maxMenuHeight={menuItemHeight * 7}
|
||||||
|
options={styleMapOptions}
|
||||||
|
value={styleMapOptions.find((o) => o.value === style)}
|
||||||
|
onChange={(option: any) => {
|
||||||
|
onSetStyle(option)
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ export type ThemeConfiguratorProps = {
|
||||||
callBackClose?: () => void
|
callBackClose?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const ThemeConfigurator = ({ callBackClose }: ThemeConfiguratorProps) => {
|
const ThemeConfigurator = ({ callBackClose }: ThemeConfiguratorProps) => {
|
||||||
const { translate } = useLocalization()
|
const { translate } = useLocalization()
|
||||||
const [modeKey, setModeKey] = useState(0)
|
const [modeKey, setModeKey] = useState(0)
|
||||||
|
|
@ -24,6 +23,10 @@ const ThemeConfigurator = ({ callBackClose }: ThemeConfiguratorProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full justify-between">
|
<div className="flex flex-col h-full justify-between">
|
||||||
<div className="flex flex-col gap-y-3 mb-2 ml-1">
|
<div className="flex flex-col gap-y-3 mb-2 ml-1">
|
||||||
|
<div>
|
||||||
|
<h6 className="mb-3">{translate('::SidePanel.Layout')}</h6>
|
||||||
|
<LayoutSwitcher />
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h6 className="mb-3">{translate('::App.SiteManagement.Theme.Style')}</h6>
|
<h6 className="mb-3">{translate('::App.SiteManagement.Theme.Style')}</h6>
|
||||||
<StyleSwitcher onStyleChange={handleStyleChange} />
|
<StyleSwitcher onStyleChange={handleStyleChange} />
|
||||||
|
|
@ -50,10 +53,6 @@ const ThemeConfigurator = ({ callBackClose }: ThemeConfiguratorProps) => {
|
||||||
</div>
|
</div>
|
||||||
<DirectionSwitcher callBackClose={callBackClose} />
|
<DirectionSwitcher callBackClose={callBackClose} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<h6 className="mb-3">{translate('::SidePanel.Layout')}</h6>
|
|
||||||
<LayoutSwitcher />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue