mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix: fix pendant color error, fixed #537
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
import React from 'react';
|
import React, {
|
||||||
|
FC,
|
||||||
|
FunctionComponent,
|
||||||
|
PropsWithChildren,
|
||||||
|
CSSProperties,
|
||||||
|
} from 'react';
|
||||||
import { Tag, type TagProps } from '@toeverything/components/ui';
|
import { Tag, type TagProps } from '@toeverything/components/ui';
|
||||||
import {
|
import {
|
||||||
DateValue,
|
DateValue,
|
||||||
@@ -18,7 +23,7 @@ import {
|
|||||||
} from '../recast-block';
|
} from '../recast-block';
|
||||||
import { IconNames, PendantTypes } from './types';
|
import { IconNames, PendantTypes } from './types';
|
||||||
import format from 'date-fns/format';
|
import format from 'date-fns/format';
|
||||||
import { IconMap, pendantColors } from './config';
|
import { IconMap, defaultPendantColors } from './config';
|
||||||
|
|
||||||
type PendantTagProps = {
|
type PendantTagProps = {
|
||||||
value: RecastBlockValue;
|
value: RecastBlockValue;
|
||||||
@@ -28,37 +33,33 @@ type PendantTagProps = {
|
|||||||
const MultiSelectRender = ({
|
const MultiSelectRender = ({
|
||||||
options,
|
options,
|
||||||
tagProps,
|
tagProps,
|
||||||
|
property,
|
||||||
}: {
|
}: {
|
||||||
options: SelectOption[];
|
options: SelectOption[];
|
||||||
tagProps: TagProps;
|
tagProps: TagProps;
|
||||||
|
property: RecastMetaProperty;
|
||||||
}) => {
|
}) => {
|
||||||
const { style, ...otherProps } = tagProps;
|
const { style, ...otherProps } = tagProps;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{options.map((option: SelectOption) => {
|
{options.map((option: SelectOption) => {
|
||||||
const Icon = IconMap[option.iconName as IconNames];
|
const { background, color, icon, content } = getOptionInfo({
|
||||||
|
option,
|
||||||
|
property,
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<Tag
|
<Tag
|
||||||
key={option.id}
|
key={option.id}
|
||||||
{...otherProps}
|
{...otherProps}
|
||||||
style={{
|
style={{
|
||||||
background: style?.background || option.background,
|
background: style?.background || background,
|
||||||
color: style?.color || option.color,
|
color: style?.color || color,
|
||||||
...style,
|
...style,
|
||||||
}}
|
}}
|
||||||
startElement={
|
startElement={icon}
|
||||||
Icon && (
|
|
||||||
<Icon
|
|
||||||
style={{
|
|
||||||
fontSize: 12,
|
|
||||||
color: style?.color || option.color,
|
|
||||||
marginRight: '4px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{option.name}
|
{content}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -66,23 +67,80 @@ const MultiSelectRender = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PendantTag = (props: PendantTagProps) => {
|
const getOptionInfo = ({
|
||||||
const { value, property, ...tagProps } = props;
|
option,
|
||||||
|
property,
|
||||||
|
}: {
|
||||||
|
option: SelectOption;
|
||||||
|
property: RecastMetaProperty;
|
||||||
|
}) => {
|
||||||
|
const { type } = property;
|
||||||
|
const {
|
||||||
|
background: defaultBackground,
|
||||||
|
color: defaultColor,
|
||||||
|
iconName: defaultIconName,
|
||||||
|
} = defaultPendantColors[type];
|
||||||
|
const Icon =
|
||||||
|
IconMap[option?.iconName as IconNames] ||
|
||||||
|
IconMap[defaultIconName as IconNames];
|
||||||
|
|
||||||
|
return {
|
||||||
|
background: option?.background || defaultBackground,
|
||||||
|
color: option?.color || defaultColor,
|
||||||
|
icon: Icon && (
|
||||||
|
<Icon
|
||||||
|
style={{
|
||||||
|
fontSize: 12,
|
||||||
|
marginRight: '4px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
content: option?.name || property.name,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const getNormalInfo = (
|
||||||
|
value: RecastBlockValue,
|
||||||
|
property: RecastMetaProperty
|
||||||
|
) => {
|
||||||
|
const type = value.type;
|
||||||
|
const {
|
||||||
|
background: defaultBackground,
|
||||||
|
color: defaultColor,
|
||||||
|
iconName: defaultIconName,
|
||||||
|
} = defaultPendantColors[type];
|
||||||
|
|
||||||
const {
|
const {
|
||||||
background: customBackground,
|
background: customBackground,
|
||||||
color: customColor,
|
color: customColor,
|
||||||
iconName,
|
iconName,
|
||||||
} = property;
|
} = property;
|
||||||
const { style: styleTagStyle, ...otherTagProps } = tagProps;
|
|
||||||
const type = value.type;
|
|
||||||
const { background: defaultBackground, color: defaultColor } =
|
|
||||||
pendantColors[type];
|
|
||||||
|
|
||||||
const background = customBackground || defaultBackground;
|
const background = customBackground || defaultBackground;
|
||||||
const color = customColor || defaultColor;
|
const color = customColor || defaultColor;
|
||||||
const Icon = IconMap[iconName as IconNames];
|
const Icon =
|
||||||
|
IconMap[iconName as IconNames] || IconMap[defaultIconName as IconNames];
|
||||||
|
|
||||||
|
return {
|
||||||
|
background,
|
||||||
|
color,
|
||||||
|
icon: Icon && (
|
||||||
|
<Icon
|
||||||
|
style={{
|
||||||
|
fontSize: 12,
|
||||||
|
marginRight: '4px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const PendantTag = (props: PendantTagProps) => {
|
||||||
|
const { value, property, ...tagProps } = props;
|
||||||
|
const { style: styleTagStyle, ...otherTagProps } = tagProps;
|
||||||
|
|
||||||
if (value.type === PendantTypes.Text) {
|
if (value.type === PendantTypes.Text) {
|
||||||
const { value: textValue } = value as TextValue;
|
const { value: textValue } = value as TextValue;
|
||||||
|
const { background, color, icon } = getNormalInfo(value, property);
|
||||||
return (
|
return (
|
||||||
<Tag
|
<Tag
|
||||||
style={{
|
style={{
|
||||||
@@ -90,17 +148,7 @@ export const PendantTag = (props: PendantTagProps) => {
|
|||||||
color,
|
color,
|
||||||
...styleTagStyle,
|
...styleTagStyle,
|
||||||
}}
|
}}
|
||||||
startElement={
|
startElement={icon}
|
||||||
Icon && (
|
|
||||||
<Icon
|
|
||||||
style={{
|
|
||||||
fontSize: 12,
|
|
||||||
color: color || '#fff',
|
|
||||||
marginRight: '4px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{...otherTagProps}
|
{...otherTagProps}
|
||||||
>
|
>
|
||||||
{textValue}
|
{textValue}
|
||||||
@@ -110,32 +158,14 @@ export const PendantTag = (props: PendantTagProps) => {
|
|||||||
|
|
||||||
if (value.type === PendantTypes.Date) {
|
if (value.type === PendantTypes.Date) {
|
||||||
const { value: dateValue } = value as DateValue;
|
const { value: dateValue } = value as DateValue;
|
||||||
if (Array.isArray(dateValue)) {
|
const { background, color, icon } = getNormalInfo(value, property);
|
||||||
return (
|
const content = Array.isArray(dateValue)
|
||||||
<Tag
|
? `${format(dateValue[0], 'yyyy-MM-dd')} ~ ${format(
|
||||||
style={{
|
dateValue[1],
|
||||||
background,
|
'yyyy-MM-dd'
|
||||||
color,
|
)}`
|
||||||
...styleTagStyle,
|
: format(dateValue, 'yyyy-MM-dd');
|
||||||
}}
|
|
||||||
startElement={
|
|
||||||
Icon && (
|
|
||||||
<Icon
|
|
||||||
style={{
|
|
||||||
fontSize: 12,
|
|
||||||
color: color || '#fff',
|
|
||||||
marginRight: '4px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{...otherTagProps}
|
|
||||||
>
|
|
||||||
{format(dateValue[0], 'yyyy-MM-dd')} ~{' '}
|
|
||||||
{format(dateValue[1], 'yyyy-MM-dd')}
|
|
||||||
</Tag>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<Tag
|
<Tag
|
||||||
style={{
|
style={{
|
||||||
@@ -143,20 +173,10 @@ export const PendantTag = (props: PendantTagProps) => {
|
|||||||
color,
|
color,
|
||||||
...styleTagStyle,
|
...styleTagStyle,
|
||||||
}}
|
}}
|
||||||
startElement={
|
startElement={icon}
|
||||||
Icon && (
|
|
||||||
<Icon
|
|
||||||
style={{
|
|
||||||
fontSize: 12,
|
|
||||||
color: color || '#fff',
|
|
||||||
marginRight: '4px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{...otherTagProps}
|
{...otherTagProps}
|
||||||
>
|
>
|
||||||
{format(dateValue, 'yyyy-MM-dd')}
|
{content}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -166,14 +186,32 @@ export const PendantTag = (props: PendantTagProps) => {
|
|||||||
const selectedOptions = (
|
const selectedOptions = (
|
||||||
property as MultiSelectProperty
|
property as MultiSelectProperty
|
||||||
).options.filter(o => multiSelectValue.includes(o.id));
|
).options.filter(o => multiSelectValue.includes(o.id));
|
||||||
|
const { style, ...otherProps } = tagProps;
|
||||||
|
|
||||||
if (selectedOptions.length) {
|
if (selectedOptions.length) {
|
||||||
return (
|
return (
|
||||||
<MultiSelectRender
|
<MultiSelectRender
|
||||||
options={selectedOptions}
|
options={selectedOptions}
|
||||||
tagProps={tagProps}
|
tagProps={tagProps}
|
||||||
|
property={property}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
const { background, color, icon } = getNormalInfo(value, property);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tag
|
||||||
|
style={{
|
||||||
|
background,
|
||||||
|
color,
|
||||||
|
...styleTagStyle,
|
||||||
|
}}
|
||||||
|
startElement={icon}
|
||||||
|
{...otherTagProps}
|
||||||
|
>
|
||||||
|
{property.name}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,28 +222,23 @@ export const PendantTag = (props: PendantTagProps) => {
|
|||||||
const option = (property as SelectProperty).options.find(
|
const option = (property as SelectProperty).options.find(
|
||||||
o => o.id === selectValue
|
o => o.id === selectValue
|
||||||
);
|
);
|
||||||
const OptionIcon = IconMap[option.iconName as IconNames];
|
|
||||||
|
const { background, color, icon, content } = getOptionInfo({
|
||||||
|
option,
|
||||||
|
property,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tag
|
<Tag
|
||||||
style={{
|
style={{
|
||||||
background: option.background,
|
background,
|
||||||
color: option.color,
|
color,
|
||||||
...style,
|
...style,
|
||||||
}}
|
}}
|
||||||
startElement={
|
startElement={icon}
|
||||||
OptionIcon && (
|
|
||||||
<OptionIcon
|
|
||||||
style={{
|
|
||||||
fontSize: 12,
|
|
||||||
color: option.color || '#fff',
|
|
||||||
marginRight: '4px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{...otherProps}
|
{...otherProps}
|
||||||
>
|
>
|
||||||
{option.name}
|
{content}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -217,35 +250,29 @@ export const PendantTag = (props: PendantTagProps) => {
|
|||||||
const option = (property as StatusProperty).options.find(
|
const option = (property as StatusProperty).options.find(
|
||||||
o => o.id === statusValue
|
o => o.id === statusValue
|
||||||
);
|
);
|
||||||
const OptionIcon = IconMap[option.iconName as IconNames];
|
const { background, color, icon, content } = getOptionInfo({
|
||||||
|
option,
|
||||||
|
property,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tag
|
<Tag
|
||||||
style={{
|
style={{
|
||||||
background: option.background,
|
background,
|
||||||
color: option.color,
|
color,
|
||||||
...style,
|
...style,
|
||||||
}}
|
}}
|
||||||
startElement={
|
startElement={icon}
|
||||||
OptionIcon && (
|
|
||||||
<OptionIcon
|
|
||||||
style={{
|
|
||||||
fontSize: 12,
|
|
||||||
color: option.color || '#fff',
|
|
||||||
marginRight: '4px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{...otherProps}
|
{...otherProps}
|
||||||
>
|
>
|
||||||
{option.name}
|
{content}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.type === PendantTypes.Mention) {
|
if (value.type === PendantTypes.Mention) {
|
||||||
const { value: mentionValue } = value as MentionValue;
|
const { value: mentionValue } = value as MentionValue;
|
||||||
|
const { background, color, icon } = getNormalInfo(value, property);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tag
|
<Tag
|
||||||
@@ -254,20 +281,10 @@ export const PendantTag = (props: PendantTagProps) => {
|
|||||||
color,
|
color,
|
||||||
...styleTagStyle,
|
...styleTagStyle,
|
||||||
}}
|
}}
|
||||||
startElement={
|
startElement={icon}
|
||||||
Icon && (
|
|
||||||
<Icon
|
|
||||||
style={{
|
|
||||||
fontSize: 12,
|
|
||||||
color: color || '#fff',
|
|
||||||
marginRight: '4px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{...otherTagProps}
|
{...otherTagProps}
|
||||||
>
|
>
|
||||||
@{mentionValue}
|
{mentionValue}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -299,17 +316,36 @@ export const PendantTag = (props: PendantTagProps) => {
|
|||||||
<MultiSelectRender
|
<MultiSelectRender
|
||||||
options={emailSelectedOptions}
|
options={emailSelectedOptions}
|
||||||
tagProps={tagProps}
|
tagProps={tagProps}
|
||||||
|
property={property}
|
||||||
/>
|
/>
|
||||||
<MultiSelectRender
|
<MultiSelectRender
|
||||||
options={phoneSelectedOptions}
|
options={phoneSelectedOptions}
|
||||||
tagProps={tagProps}
|
tagProps={tagProps}
|
||||||
|
property={property}
|
||||||
/>
|
/>
|
||||||
<MultiSelectRender
|
<MultiSelectRender
|
||||||
options={locationSelectedOptions}
|
options={locationSelectedOptions}
|
||||||
tagProps={tagProps}
|
tagProps={tagProps}
|
||||||
|
property={property}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
const { background, color, icon } = getNormalInfo(value, property);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tag
|
||||||
|
style={{
|
||||||
|
background,
|
||||||
|
color,
|
||||||
|
...styleTagStyle,
|
||||||
|
}}
|
||||||
|
startElement={icon}
|
||||||
|
{...otherTagProps}
|
||||||
|
>
|
||||||
|
{property.name}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
PendantIconConfig,
|
PendantConfig,
|
||||||
PendantOptions,
|
PendantOptions,
|
||||||
PendantTypes,
|
PendantTypes,
|
||||||
IconNames,
|
IconNames,
|
||||||
@@ -34,34 +34,41 @@ import {
|
|||||||
// { background: '#E3DEFF', color: '#511AAB' },
|
// { background: '#E3DEFF', color: '#511AAB' },
|
||||||
// ];
|
// ];
|
||||||
|
|
||||||
export const pendantColors = {
|
export const defaultPendantColors = {
|
||||||
[PendantTypes.Text]: {
|
[PendantTypes.Text]: {
|
||||||
background: '#7389FD',
|
iconName: IconNames.TEXT,
|
||||||
|
background: '#67dcaa',
|
||||||
color: '#FFF',
|
color: '#FFF',
|
||||||
},
|
},
|
||||||
[PendantTypes.Date]: {
|
[PendantTypes.Date]: {
|
||||||
background: '#5DC6CD',
|
iconName: IconNames.DATE,
|
||||||
|
background: '#6880FF',
|
||||||
color: '#FFF',
|
color: '#FFF',
|
||||||
},
|
},
|
||||||
[PendantTypes.Select]: {
|
[PendantTypes.Select]: {
|
||||||
background: '#EAAE14',
|
iconName: IconNames.SINGLE_SELECT,
|
||||||
color: '#FFF',
|
background: '#C3DBFF',
|
||||||
|
color: '#253486',
|
||||||
},
|
},
|
||||||
[PendantTypes.MultiSelect]: {
|
[PendantTypes.MultiSelect]: {
|
||||||
background: '#A691FC',
|
iconName: IconNames.MULTI_SELECT,
|
||||||
color: '#FFF',
|
background: '#C6F1F3',
|
||||||
|
color: '#0C6066',
|
||||||
},
|
},
|
||||||
[PendantTypes.Mention]: {
|
[PendantTypes.Mention]: {
|
||||||
background: '#57C696',
|
iconName: IconNames.COLLABORATOR,
|
||||||
|
background: '#FFD568',
|
||||||
color: '#FFF',
|
color: '#FFF',
|
||||||
},
|
},
|
||||||
[PendantTypes.Status]: {
|
[PendantTypes.Status]: {
|
||||||
background: '#57C696',
|
iconName: IconNames.STATUS,
|
||||||
color: '#FFF',
|
background: '#C5FBE0',
|
||||||
|
color: '#05683D',
|
||||||
},
|
},
|
||||||
[PendantTypes.Information]: {
|
[PendantTypes.Information]: {
|
||||||
background: '#57C696',
|
iconName: IconNames.INFORMATION,
|
||||||
color: '#FFF',
|
background: '#ffcca7',
|
||||||
|
color: '#8f4400',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -78,20 +85,24 @@ export const IconMap = {
|
|||||||
[IconNames.EMAIL]: EmailIcon,
|
[IconNames.EMAIL]: EmailIcon,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const pendantIconConfig: { [key: string]: PendantIconConfig } = {
|
export const pendantConfig: { [key: string]: PendantConfig } = {
|
||||||
[PendantTypes.Text]: {
|
[PendantTypes.Text]: {
|
||||||
name: IconNames.TEXT,
|
iconName: IconNames.TEXT,
|
||||||
background: '#67dcaa',
|
background: '#67dcaa',
|
||||||
color: '#FFF',
|
color: '#FFF',
|
||||||
},
|
},
|
||||||
[PendantTypes.Date]: { name: IconNames.DATE, background: '', color: '' },
|
[PendantTypes.Date]: {
|
||||||
|
iconName: IconNames.DATE,
|
||||||
|
background: '#6880FF',
|
||||||
|
color: '#fff',
|
||||||
|
},
|
||||||
[PendantTypes.Status]: {
|
[PendantTypes.Status]: {
|
||||||
name: IconNames.STATUS,
|
iconName: IconNames.STATUS,
|
||||||
background: ['#C5FBE0', '#FFF5AB', '#FFCECE', '#E3DEFF'],
|
background: ['#C5FBE0', '#FFF5AB', '#FFCECE', '#E3DEFF'],
|
||||||
color: ['#05683D', '#896406', '#AF1212', '#511AAB'],
|
color: ['#05683D', '#896406', '#AF1212', '#511AAB'],
|
||||||
},
|
},
|
||||||
[PendantTypes.Select]: {
|
[PendantTypes.Select]: {
|
||||||
name: IconNames.SINGLE_SELECT,
|
iconName: IconNames.SINGLE_SELECT,
|
||||||
background: [
|
background: [
|
||||||
'#C3DBFF',
|
'#C3DBFF',
|
||||||
'#C6F1F3',
|
'#C6F1F3',
|
||||||
@@ -113,7 +124,7 @@ export const pendantIconConfig: { [key: string]: PendantIconConfig } = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PendantTypes.MultiSelect]: {
|
[PendantTypes.MultiSelect]: {
|
||||||
name: IconNames.MULTI_SELECT,
|
iconName: IconNames.MULTI_SELECT,
|
||||||
background: [
|
background: [
|
||||||
'#C3DBFF',
|
'#C3DBFF',
|
||||||
'#C6F1F3',
|
'#C6F1F3',
|
||||||
@@ -134,27 +145,27 @@ export const pendantIconConfig: { [key: string]: PendantIconConfig } = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
[PendantTypes.Mention]: {
|
[PendantTypes.Mention]: {
|
||||||
name: IconNames.COLLABORATOR,
|
iconName: IconNames.COLLABORATOR,
|
||||||
background: '#FFD568',
|
background: '#FFD568',
|
||||||
color: '#FFFFFF',
|
color: '#FFFFFF',
|
||||||
},
|
},
|
||||||
[PendantTypes.Information]: {
|
[PendantTypes.Information]: {
|
||||||
name: IconNames.INFORMATION,
|
iconName: IconNames.INFORMATION,
|
||||||
background: '#FFD568',
|
background: '#FFD568',
|
||||||
color: '#FFFFFF',
|
color: '#FFFFFF',
|
||||||
},
|
},
|
||||||
Phone: {
|
Phone: {
|
||||||
name: IconNames.PHONE,
|
iconName: IconNames.PHONE,
|
||||||
background: '#c3dbff',
|
background: '#c3dbff',
|
||||||
color: '#263486',
|
color: '#263486',
|
||||||
},
|
},
|
||||||
Location: {
|
Location: {
|
||||||
name: IconNames.LOCATION,
|
iconName: IconNames.LOCATION,
|
||||||
background: '#c5f1f3',
|
background: '#c5f1f3',
|
||||||
color: '#263486',
|
color: '#263486',
|
||||||
},
|
},
|
||||||
Email: {
|
Email: {
|
||||||
name: IconNames.EMAIL,
|
iconName: IconNames.EMAIL,
|
||||||
background: '#ffcca7',
|
background: '#ffcca7',
|
||||||
color: '#8f4400',
|
color: '#8f4400',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export default ({
|
|||||||
placeholder={
|
placeholder={
|
||||||
<>
|
<>
|
||||||
<PendantIcon
|
<PendantIcon
|
||||||
iconName={iconConfig?.name}
|
iconName={iconConfig?.iconName}
|
||||||
color={iconConfig?.color as CSSProperties['color']}
|
color={iconConfig?.color as CSSProperties['color']}
|
||||||
background={
|
background={
|
||||||
iconConfig?.background as CSSProperties['background']
|
iconConfig?.background as CSSProperties['background']
|
||||||
|
|||||||
@@ -9,12 +9,8 @@ import { Add, Delete, Close } from '@mui/icons-material';
|
|||||||
import { ModifyPanelContentProps } from './types';
|
import { ModifyPanelContentProps } from './types';
|
||||||
import {
|
import {
|
||||||
MultiSelectProperty,
|
MultiSelectProperty,
|
||||||
MultiSelectValue,
|
|
||||||
SelectOption,
|
|
||||||
SelectProperty,
|
SelectProperty,
|
||||||
SelectOptionId,
|
SelectOptionId,
|
||||||
RecastBlockValue,
|
|
||||||
RecastMetaProperty,
|
|
||||||
} from '../../recast-block';
|
} from '../../recast-block';
|
||||||
import {
|
import {
|
||||||
Checkbox,
|
Checkbox,
|
||||||
@@ -24,12 +20,7 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
} from '@toeverything/components/ui';
|
} from '@toeverything/components/ui';
|
||||||
import { HighLightIconInput } from './IconInput';
|
import { HighLightIconInput } from './IconInput';
|
||||||
import {
|
import { PendantConfig, IconNames, OptionIdType, OptionType } from '../types';
|
||||||
PendantIconConfig,
|
|
||||||
IconNames,
|
|
||||||
OptionIdType,
|
|
||||||
OptionType,
|
|
||||||
} from '../types';
|
|
||||||
import { genBasicOption } from '../utils';
|
import { genBasicOption } from '../utils';
|
||||||
|
|
||||||
type OptionItemType = {
|
type OptionItemType = {
|
||||||
@@ -67,7 +58,7 @@ export const BasicSelect = ({
|
|||||||
initialOptions: OptionType[];
|
initialOptions: OptionType[];
|
||||||
onValueChange: (value: any) => void;
|
onValueChange: (value: any) => void;
|
||||||
onPropertyChange?: (newProperty: any) => void;
|
onPropertyChange?: (newProperty: any) => void;
|
||||||
iconConfig?: PendantIconConfig;
|
iconConfig?: PendantConfig;
|
||||||
onEnter?: (e: KeyboardEvent) => void;
|
onEnter?: (e: KeyboardEvent) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const [options, setOptions] = useState<OptionType[]>(initialOptions);
|
const [options, setOptions] = useState<OptionType[]>(initialOptions);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default ({
|
|||||||
const [text, setText] = useState(initialValue?.value || '');
|
const [text, setText] = useState(initialValue?.value || '');
|
||||||
return (
|
return (
|
||||||
<HighLightIconInput
|
<HighLightIconInput
|
||||||
iconName={iconConfig?.name}
|
iconName={iconConfig?.iconName}
|
||||||
color={iconConfig?.color as CSSProperties['color']}
|
color={iconConfig?.color as CSSProperties['color']}
|
||||||
background={iconConfig?.background as CSSProperties['background']}
|
background={iconConfig?.background as CSSProperties['background']}
|
||||||
value={text}
|
value={text}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { OptionType, PendantIconConfig, PendantTypes } from '../types';
|
import { OptionType, PendantConfig, PendantTypes } from '../types';
|
||||||
import type { RecastBlockValue, RecastMetaProperty } from '../../recast-block';
|
import type { RecastBlockValue, RecastMetaProperty } from '../../recast-block';
|
||||||
import { FunctionComponent } from 'react';
|
|
||||||
|
|
||||||
export type ModifyPanelProps = {
|
export type ModifyPanelProps = {
|
||||||
type: PendantTypes | PendantTypes[];
|
type: PendantTypes | PendantTypes[];
|
||||||
@@ -9,7 +8,7 @@ export type ModifyPanelProps = {
|
|||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
initialValue?: RecastBlockValue;
|
initialValue?: RecastBlockValue;
|
||||||
initialOptions?: OptionType[];
|
initialOptions?: OptionType[];
|
||||||
iconConfig?: PendantIconConfig;
|
iconConfig?: PendantConfig;
|
||||||
isStatusSelect?: boolean;
|
isStatusSelect?: boolean;
|
||||||
property?: RecastMetaProperty;
|
property?: RecastMetaProperty;
|
||||||
};
|
};
|
||||||
@@ -20,7 +19,7 @@ export type ModifyPanelContentProps = {
|
|||||||
onPropertyChange?: (newProperty: any) => void;
|
onPropertyChange?: (newProperty: any) => void;
|
||||||
initialValue?: RecastBlockValue;
|
initialValue?: RecastBlockValue;
|
||||||
initialOptions?: OptionType[];
|
initialOptions?: OptionType[];
|
||||||
iconConfig?: PendantIconConfig;
|
iconConfig?: PendantConfig;
|
||||||
isStatusSelect?: boolean;
|
isStatusSelect?: boolean;
|
||||||
property?: RecastMetaProperty;
|
property?: RecastMetaProperty;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Input, Option, Select, Tooltip } from '@toeverything/components/ui';
|
|||||||
import { HelpCenterIcon } from '@toeverything/components/icons';
|
import { HelpCenterIcon } from '@toeverything/components/icons';
|
||||||
import { AsyncBlock } from '../../editor';
|
import { AsyncBlock } from '../../editor';
|
||||||
|
|
||||||
import { pendantOptions, IconMap, pendantIconConfig } from '../config';
|
import { pendantOptions, IconMap } from '../config';
|
||||||
import { OptionType, PendantOptions, PendantTypes } from '../types';
|
import { OptionType, PendantOptions, PendantTypes } from '../types';
|
||||||
import { PendantModifyPanel } from '../pendant-modify-panel';
|
import { PendantModifyPanel } from '../pendant-modify-panel';
|
||||||
import {
|
import {
|
||||||
@@ -25,7 +25,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
genInitialOptions,
|
genInitialOptions,
|
||||||
getOfficialSelected,
|
getOfficialSelected,
|
||||||
getPendantIconsConfigByType,
|
getPendantConfigByType,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { usePendant } from '../use-pendant';
|
import { usePendant } from '../use-pendant';
|
||||||
|
|
||||||
@@ -101,9 +101,9 @@ export const CreatePendantPanel = ({
|
|||||||
// Select, MultiSelect, Status use this props as initial property
|
// Select, MultiSelect, Status use this props as initial property
|
||||||
initialOptions={genInitialOptions(
|
initialOptions={genInitialOptions(
|
||||||
selectedOption.type,
|
selectedOption.type,
|
||||||
getPendantIconsConfigByType(selectedOption.type)
|
getPendantConfigByType(selectedOption.type)
|
||||||
)}
|
)}
|
||||||
iconConfig={getPendantIconsConfigByType(
|
iconConfig={getPendantConfigByType(
|
||||||
selectedOption.type
|
selectedOption.type
|
||||||
)}
|
)}
|
||||||
// isStatusSelect={selectedOption.name === 'Status'}
|
// isStatusSelect={selectedOption.name === 'Status'}
|
||||||
@@ -178,7 +178,7 @@ export const CreatePendantPanel = ({
|
|||||||
} else {
|
} else {
|
||||||
// TODO: Color and background should use pendant config, but ui is not design now
|
// TODO: Color and background should use pendant config, but ui is not design now
|
||||||
const iconConfig =
|
const iconConfig =
|
||||||
getPendantIconsConfigByType(type);
|
getPendantConfigByType(type);
|
||||||
// TODO: Color and background should be choose by user in the future
|
// TODO: Color and background should be choose by user in the future
|
||||||
const newProperty = await addProperty({
|
const newProperty = await addProperty({
|
||||||
type: type,
|
type: type,
|
||||||
@@ -186,7 +186,7 @@ export const CreatePendantPanel = ({
|
|||||||
background:
|
background:
|
||||||
iconConfig.background as CSSProperties['background'],
|
iconConfig.background as CSSProperties['background'],
|
||||||
color: iconConfig.color as CSSProperties['color'],
|
color: iconConfig.color as CSSProperties['color'],
|
||||||
iconName: iconConfig.name,
|
iconName: iconConfig.iconName,
|
||||||
});
|
});
|
||||||
|
|
||||||
await setPendant(newProperty, newValue);
|
await setPendant(newProperty, newValue);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
import { OptionType, PendantTypes, TempInformationType } from '../types';
|
import { OptionType, PendantTypes, TempInformationType } from '../types';
|
||||||
import {
|
import {
|
||||||
getOfficialSelected,
|
getOfficialSelected,
|
||||||
getPendantIconsConfigByType,
|
getPendantConfigByType,
|
||||||
// getPendantIconsConfigByNameOrType,
|
// getPendantIconsConfigByNameOrType,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { usePendant } from '../use-pendant';
|
import { usePendant } from '../use-pendant';
|
||||||
@@ -52,8 +52,8 @@ export const UpdatePendantPanel = ({
|
|||||||
const { updateSelect } = useSelectProperty();
|
const { updateSelect } = useSelectProperty();
|
||||||
const { setPendant, removePendant } = usePendant(block);
|
const { setPendant, removePendant } = usePendant(block);
|
||||||
const pendantOption = pendantOptions.find(v => v.type === property.type);
|
const pendantOption = pendantOptions.find(v => v.type === property.type);
|
||||||
const iconConfig = getPendantIconsConfigByType(property.type);
|
const iconConfig = getPendantConfigByType(property.type);
|
||||||
const Icon = IconMap[iconConfig.name];
|
const Icon = IconMap[iconConfig.iconName];
|
||||||
const { updateProperty } = useRecastBlockMeta();
|
const { updateProperty } = useRecastBlockMeta();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -84,7 +84,7 @@ export const UpdatePendantPanel = ({
|
|||||||
value: value.value,
|
value: value.value,
|
||||||
} as RecastBlockValue
|
} as RecastBlockValue
|
||||||
}
|
}
|
||||||
iconConfig={getPendantIconsConfigByType(property.type)}
|
iconConfig={getPendantConfigByType(property.type)}
|
||||||
property={property}
|
property={property}
|
||||||
type={property.type}
|
type={property.type}
|
||||||
onSure={async (type, newPropertyItem, newValue) => {
|
onSure={async (type, newPropertyItem, newValue) => {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
import { Popover, PopperHandler, styled } from '@toeverything/components/ui';
|
import { Popover, PopperHandler, styled } from '@toeverything/components/ui';
|
||||||
import { PendantTag } from '../PendantTag';
|
import { PendantTag } from '../PendantTag';
|
||||||
|
|
||||||
import { pendantColors } from '../config';
|
import { defaultPendantColors } from '../config';
|
||||||
import { UpdatePendantPanel } from '../pendant-operation-panel';
|
import { UpdatePendantPanel } from '../pendant-operation-panel';
|
||||||
import { AddPendantPopover } from '../AddPendantPopover';
|
import { AddPendantPopover } from '../AddPendantPopover';
|
||||||
import { PendantTypes } from '../types';
|
import { PendantTypes } from '../types';
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ export type PendantOptions = {
|
|||||||
subTitle: string;
|
subTitle: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PendantIconConfig = {
|
export type PendantConfig = {
|
||||||
name: IconNames;
|
iconName: IconNames;
|
||||||
// background: CSSProperties['background'];
|
// background: CSSProperties['background'];
|
||||||
// color: CSSProperties['color'];
|
// color: CSSProperties['color'];
|
||||||
background: CSSProperties['background'] | CSSProperties['background'][];
|
background: CSSProperties['background'] | CSSProperties['background'][];
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
PropertyType,
|
|
||||||
RecastBlockValue,
|
RecastBlockValue,
|
||||||
RecastPropertyId,
|
RecastPropertyId,
|
||||||
RecastMetaProperty,
|
|
||||||
SelectOption,
|
SelectOption,
|
||||||
SelectOptionId,
|
|
||||||
} from '../recast-block';
|
} from '../recast-block';
|
||||||
import { OptionIdType, OptionType } from './types';
|
import { OptionIdType, OptionType } from './types';
|
||||||
import { pendantIconConfig } from './config';
|
import { pendantConfig } from './config';
|
||||||
import { PendantIconConfig, PendantTypes } from './types';
|
import { PendantConfig, PendantTypes } from './types';
|
||||||
type Props = {
|
type Props = {
|
||||||
recastBlockId: string;
|
recastBlockId: string;
|
||||||
blockId: string;
|
blockId: string;
|
||||||
@@ -24,12 +21,12 @@ type StorageMap = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const LOCAL_STROAGE_NAME = 'TEMPORARY_PENDANT_DATA';
|
const LOCAL_STORAGE_NAME = 'TEMPORARY_PENDANT_DATA';
|
||||||
|
|
||||||
const ensureLocalStorage = () => {
|
const ensureLocalStorage = () => {
|
||||||
const data = localStorage.getItem(LOCAL_STROAGE_NAME);
|
const data = localStorage.getItem(LOCAL_STORAGE_NAME);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
localStorage.setItem(LOCAL_STROAGE_NAME, JSON.stringify({}));
|
localStorage.setItem(LOCAL_STORAGE_NAME, JSON.stringify({}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,7 +37,7 @@ export const setLatestPropertyValue = ({
|
|||||||
}: Props) => {
|
}: Props) => {
|
||||||
ensureLocalStorage();
|
ensureLocalStorage();
|
||||||
const data: StorageMap = JSON.parse(
|
const data: StorageMap = JSON.parse(
|
||||||
localStorage.getItem(LOCAL_STROAGE_NAME) as string
|
localStorage.getItem(LOCAL_STORAGE_NAME) as string
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!data[recastBlockId]) {
|
if (!data[recastBlockId]) {
|
||||||
@@ -53,7 +50,7 @@ export const setLatestPropertyValue = ({
|
|||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
|
|
||||||
localStorage.setItem(LOCAL_STROAGE_NAME, JSON.stringify(data));
|
localStorage.setItem(LOCAL_STORAGE_NAME, JSON.stringify(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getLatestPropertyValue = ({
|
export const getLatestPropertyValue = ({
|
||||||
@@ -68,7 +65,7 @@ export const getLatestPropertyValue = ({
|
|||||||
}> => {
|
}> => {
|
||||||
ensureLocalStorage();
|
ensureLocalStorage();
|
||||||
const data: StorageMap = JSON.parse(
|
const data: StorageMap = JSON.parse(
|
||||||
localStorage.getItem(LOCAL_STROAGE_NAME) as string
|
localStorage.getItem(LOCAL_STORAGE_NAME) as string
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!data[recastBlockId]) {
|
if (!data[recastBlockId]) {
|
||||||
@@ -95,7 +92,7 @@ export const removePropertyValueRecord = ({
|
|||||||
}) => {
|
}) => {
|
||||||
ensureLocalStorage();
|
ensureLocalStorage();
|
||||||
const data: StorageMap = JSON.parse(
|
const data: StorageMap = JSON.parse(
|
||||||
localStorage.getItem(LOCAL_STROAGE_NAME) as string
|
localStorage.getItem(LOCAL_STORAGE_NAME) as string
|
||||||
);
|
);
|
||||||
if (!data[recastBlockId]) {
|
if (!data[recastBlockId]) {
|
||||||
return;
|
return;
|
||||||
@@ -103,7 +100,7 @@ export const removePropertyValueRecord = ({
|
|||||||
|
|
||||||
delete data[recastBlockId][propertyId];
|
delete data[recastBlockId][propertyId];
|
||||||
|
|
||||||
localStorage.setItem(LOCAL_STROAGE_NAME, JSON.stringify(data));
|
localStorage.setItem(LOCAL_STORAGE_NAME, JSON.stringify(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +143,14 @@ export const getOfficialSelected = ({
|
|||||||
return selectedId;
|
return selectedId;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPendantIconsConfigByType = (
|
export const getPendantConfigByType = (pendantType: string): PendantConfig => {
|
||||||
pendantType: string
|
return pendantConfig[pendantType];
|
||||||
): PendantIconConfig => {
|
|
||||||
return pendantIconConfig[pendantType];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPendantIconsConfigByName = (
|
export const getPendantIconsConfigByName = (
|
||||||
pendantName?: string
|
pendantName?: string
|
||||||
): PendantIconConfig => {
|
): PendantConfig => {
|
||||||
return pendantIconConfig[pendantName];
|
return pendantConfig[pendantName];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const genBasicOption = ({
|
export const genBasicOption = ({
|
||||||
@@ -164,10 +159,10 @@ export const genBasicOption = ({
|
|||||||
name = '',
|
name = '',
|
||||||
}: {
|
}: {
|
||||||
index: number;
|
index: number;
|
||||||
iconConfig: PendantIconConfig;
|
iconConfig: PendantConfig;
|
||||||
name?: string;
|
name?: string;
|
||||||
}): OptionType => {
|
}): OptionType => {
|
||||||
const iconName = iconConfig.name;
|
const iconName = iconConfig.iconName;
|
||||||
const background = Array.isArray(iconConfig.background)
|
const background = Array.isArray(iconConfig.background)
|
||||||
? iconConfig.background[index % iconConfig.background.length]
|
? iconConfig.background[index % iconConfig.background.length]
|
||||||
: iconConfig.background;
|
: iconConfig.background;
|
||||||
@@ -189,7 +184,7 @@ export const genBasicOption = ({
|
|||||||
* **/
|
* **/
|
||||||
export const genInitialOptions = (
|
export const genInitialOptions = (
|
||||||
type: PendantTypes,
|
type: PendantTypes,
|
||||||
iconConfig: PendantIconConfig
|
iconConfig: PendantConfig
|
||||||
) => {
|
) => {
|
||||||
if (type === PendantTypes.Status) {
|
if (type === PendantTypes.Status) {
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user