Add trad for single value

This commit is contained in:
soupette 2019-12-04 18:57:06 +01:00
parent bdf708d6eb
commit c8d09821c7
6 changed files with 41 additions and 8 deletions

View File

@ -13,6 +13,7 @@ const MenuList = ({
name, name,
onClickOption, onClickOption,
refState, refState,
value,
}, },
...rest ...rest
}) => { }) => {
@ -50,6 +51,8 @@ const MenuList = ({
return null; return null;
} }
const isSelected = value.value === component.uid;
return ( return (
<li <li
key={component.uid} key={component.uid}
@ -61,7 +64,13 @@ const MenuList = ({
}); });
}} }}
> >
<p datadescr={upperFirst(component.schema.name)}> <p
datadescr={upperFirst(component.schema.name)}
style={{
color: isSelected ? '#007eff' : '',
fontWeight: isSelected ? '700' : '400',
}}
>
{upperFirst(component.schema.name)} {upperFirst(component.schema.name)}
</p> </p>
</li> </li>
@ -86,6 +95,9 @@ MenuList.defaultProps = {
}, },
}, },
}, },
value: {
value: '',
},
}, },
}; };
@ -95,6 +107,7 @@ MenuList.propTypes = {
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
onClickOption: PropTypes.func.isRequired, onClickOption: PropTypes.func.isRequired,
refState: PropTypes.object, refState: PropTypes.object,
value: PropTypes.object,
}).isRequired, }).isRequired,
}; };

View File

@ -1,8 +1,10 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { components } from 'react-select'; import { components } from 'react-select';
import { get } from 'lodash'; import { get, size } from 'lodash';
import { FormattedMessage } from 'react-intl';
import useDataManager from '../../hooks/useDataManager'; import useDataManager from '../../hooks/useDataManager';
import getTrad from '../../utils/getTrad';
import UpperFirst from '../UpperFirst'; import UpperFirst from '../UpperFirst';
const Value = ({ children, ...props }) => { const Value = ({ children, ...props }) => {
@ -29,6 +31,11 @@ const Value = ({ children, ...props }) => {
const displayedCategory = isCreatingComponent ? componentCategory : category; const displayedCategory = isCreatingComponent ? componentCategory : category;
const displayedName = isCreatingComponent ? componentName : name; const displayedName = isCreatingComponent ? componentName : name;
const style = { color: '#333740' }; const style = { color: '#333740' };
const valueLength = size(value);
const message =
valueLength > '0'
? getTrad('components.componentSelect.value-components')
: getTrad('components.componentSelect.value-components');
return ( return (
<SingleValue {...props}> <SingleValue {...props}>
@ -42,7 +49,9 @@ const Value = ({ children, ...props }) => {
</> </>
)} )}
{isMultiple && ( {isMultiple && (
<span style={style}>{value.length} components selected</span> <FormattedMessage id={message} values={{ number: valueLength }}>
{msg => <span style={style}>{msg}</span>}
</FormattedMessage>
)} )}
</SingleValue> </SingleValue>
); );

View File

@ -30,6 +30,7 @@ const CreatableSelect = ({ onChange, name, styles, value }) => {
<Creatable <Creatable
value={getValue()} value={getValue()}
isClearable isClearable
// menuIsOpen
onChange={handleChange} onChange={handleChange}
styles={styles} styles={styles}
options={formatOptions()} options={formatOptions()}

View File

@ -8,7 +8,7 @@ import React, { useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { TabContent, TabPane, Nav } from 'reactstrap'; import { TabContent, TabPane, Nav } from 'reactstrap';
import { Plus } from '@buffetjs/icons'; // import { Plus } from '@buffetjs/icons';
import getTrad from '../../utils/getTrad'; import getTrad from '../../utils/getTrad';
import ComponentList from '../ComponentList'; import ComponentList from '../ComponentList';
@ -29,9 +29,7 @@ function DynamicZoneList({ customRowComponent, components, addComponent }) {
<Nav tabs> <Nav tabs>
<li> <li>
<ComponentButton onClick={addComponent}> <ComponentButton onClick={addComponent}>
<div> <div>{/* <Plus /> */}+</div>
<Plus />
</div>
<p> <p>
<FormattedMessage id={getTrad('button.component.add')} /> <FormattedMessage id={getTrad('button.component.add')} />
</p> </p>

View File

@ -28,6 +28,16 @@ const WrapperSelect = ({ error, label, name, type, ...rest }) => {
borderTopColor: '#E3E9F3 !important', borderTopColor: '#E3E9F3 !important',
}; };
}, },
option: (base, state) => {
console.log({ base, state });
return {
...base,
// backgroundColor: state.isSelected ? '#DEEBFF' : base.backgroundColor,
backgroundColor: '#fff',
color: state.isSelected ? '#007eff' : '#333740',
fontWeight: state.isSelected ? '600' : '400',
};
},
}; };
const Component = const Component =

View File

@ -272,5 +272,7 @@
"modalForm.sub-header.addComponentToDynamicZone": "Add new component to the dynamic zone", "modalForm.sub-header.addComponentToDynamicZone": "Add new component to the dynamic zone",
"popUpWarning.bodyMessage.cancel-modifications": "Are you sure you want to cancel your modifications?", "popUpWarning.bodyMessage.cancel-modifications": "Are you sure you want to cancel your modifications?",
"popUpWarning.bodyMessage.cancel-modifications.with-components": "Are you sure you want to cancel your modifications? Some components have been created or modified...", "popUpWarning.bodyMessage.cancel-modifications.with-components": "Are you sure you want to cancel your modifications? Some components have been created or modified...",
"prompt.unsaved": "Are you sure you want to leave? All your modifications will be lost." "prompt.unsaved": "Are you sure you want to leave? All your modifications will be lost.",
"components.componentSelect.value-components": "{number} components selected",
"components.componentSelect.value-component": "{number} component selected"
} }