diff --git a/packages/strapi-helper-plugin/lib/src/components/Tabs/TabComponents.js b/packages/strapi-helper-plugin/lib/src/components/Tabs/TabComponents.js new file mode 100644 index 0000000000..3815b781fb --- /dev/null +++ b/packages/strapi-helper-plugin/lib/src/components/Tabs/TabComponents.js @@ -0,0 +1,37 @@ +import React from 'react'; +import styled from 'styled-components'; +import { Flex, Text } from '@buffetjs/core'; + +export const TabNavRaw = styled(props => )` + width: 100%; +`; + +export const TabsRaw = styled(props => ( + +))` + width: 100%; + margin-left: ${({ position }) => (position === 'right' ? 'auto' : 0)}; + border-bottom: 1px solid ${({ theme }) => theme.main.colors.brightGrey}; +`; + +export const TabButton = styled(props => ( + +))` + height: 3.8rem; + letter-spacing: 0.7px; + margin-left: 3rem; + border-bottom: 2px solid + ${props => (props['aria-selected'] ? props.theme.main.colors.mediumBlue : 'transparent')}; + padding: 0; +`; + +export const TabPanelRaw = styled.div` + padding: 2.2rem 0; +`; diff --git a/packages/strapi-helper-plugin/lib/src/components/Tabs/index.js b/packages/strapi-helper-plugin/lib/src/components/Tabs/index.js new file mode 100644 index 0000000000..e0730f26b0 --- /dev/null +++ b/packages/strapi-helper-plugin/lib/src/components/Tabs/index.js @@ -0,0 +1,129 @@ +import React, { createContext, useContext, useState } from 'react'; +import PropTypes from 'prop-types'; +import { TabNavRaw, TabButton, TabsRaw, TabPanelRaw } from './TabComponents'; + +const TabsIndexContext = createContext({ selectedIndex: 0, setSelectedIndex: () => undefined }); +const TabsIdContext = createContext(null); + +export const TabsNav = ({ children, defaultSelection, label, id }) => { + const [selectedIndex, setSelectedIndex] = useState(defaultSelection); + + return ( + + + + {children} + + + + ); +}; + +TabsNav.propTypes = { + id: PropTypes.string.isRequired, + children: PropTypes.node.isRequired, + label: PropTypes.string.isRequired, + defaultSelection: PropTypes.number.isRequired, +}; + +export const Tabs = ({ children, position }) => { + const id = useContext(TabsIdContext); + const { setSelectedIndex, selectedIndex } = useContext(TabsIndexContext); + const childrenArray = React.Children.toArray(children); + + return ( + + {childrenArray.map((child, index) => + React.cloneElement(child, { + onSelect: () => setSelectedIndex(index), + selected: index === selectedIndex, + id: `${id}-${index}`, + }) + )} + + ); +}; + +Tabs.defaultProps = { + position: 'left', +}; + +Tabs.propTypes = { + children: PropTypes.node.isRequired, + position: PropTypes.oneOf(['left', 'right']), +}; + +export const TabsPanel = ({ children }) => { + const { selectedIndex } = useContext(TabsIndexContext); + const id = useContext(TabsIdContext); + const childrenArray = React.Children.toArray(children); + + return ( + <> + {childrenArray.map((child, index) => + React.cloneElement(child, { selected: index === selectedIndex, id: `${id}-${index}` }) + )} + + ); +}; + +TabsPanel.propTypes = { + children: PropTypes.node.isRequired, +}; + +export const Tab = ({ children, selected, onSelect, id }) => { + const ariaControls = `${id}-tabpanel`; + + return ( + + {children} + + ); +}; + +Tab.defaultProps = { + selected: false, + id: '', + onSelect: () => undefined, +}; + +Tab.propTypes = { + children: PropTypes.node.isRequired, + selected: PropTypes.bool, + onSelect: PropTypes.func, + id: PropTypes.string, +}; + +export const TabPanel = ({ children, selected, id }) => { + const labelledBy = `${id}-tab`; + + return ( + + ); +}; + +TabPanel.defaultProps = { + id: '', + selected: false, +}; + +TabPanel.propTypes = { + children: PropTypes.node.isRequired, + selected: PropTypes.bool, + id: PropTypes.string, +}; diff --git a/packages/strapi-helper-plugin/lib/src/index.js b/packages/strapi-helper-plugin/lib/src/index.js index e0c835f2f4..74d286b69a 100644 --- a/packages/strapi-helper-plugin/lib/src/index.js +++ b/packages/strapi-helper-plugin/lib/src/index.js @@ -25,6 +25,7 @@ export { default as HeaderSearch } from './components/HeaderSearch'; export { default as IcoContainer } from './components/IcoContainer'; export { default as InputAddon } from './components/InputAddon'; export { default as EmptyState } from './components/EmptyState'; +export * from './components/Tabs'; export { default as InputAddonWithErrors } from './components/InputAddonWithErrors'; export { default as InputCheckbox } from './components/InputCheckbox'; diff --git a/packages/strapi-plugin-i18n/admin/src/components/LocaleRow/index.js b/packages/strapi-plugin-i18n/admin/src/components/LocaleRow/index.js index 1112323e7c..d56e519923 100644 --- a/packages/strapi-plugin-i18n/admin/src/components/LocaleRow/index.js +++ b/packages/strapi-plugin-i18n/admin/src/components/LocaleRow/index.js @@ -30,12 +30,15 @@ const LocaleSettingsPage = ({ locale, onDelete, onEdit }) => { ) : null, - onClick: () => onDelete(locale), + onClick: e => { + e.stopPropagation(); + onDelete(locale); + }, }); } return ( - + onEdit(locale)}> {locale.code} diff --git a/packages/strapi-plugin-i18n/admin/src/components/ModalEdit/BaseForm.js b/packages/strapi-plugin-i18n/admin/src/components/ModalEdit/BaseForm.js new file mode 100644 index 0000000000..833597abd5 --- /dev/null +++ b/packages/strapi-plugin-i18n/admin/src/components/ModalEdit/BaseForm.js @@ -0,0 +1,73 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Label } from '@buffetjs/core'; +import { Inputs } from '@buffetjs/custom'; +import Select from 'react-select'; +import { Col, Row } from 'reactstrap'; +import { useIntl } from 'react-intl'; +import { useFormikContext } from 'formik'; +import { getTrad } from '../../utils'; + +const BaseForm = ({ options, defaultOption }) => { + const { formatMessage } = useIntl(); + const { values, handleChange } = useFormikContext(); + + return ( + + + + + + + - - -
-