From 836d016a737266f0f3cb1a4045b628f418518474 Mon Sep 17 00:00:00 2001 From: soupette Date: Mon, 6 Apr 2020 13:36:04 +0200 Subject: [PATCH] Add back button event Signed-off-by: soupette --- .../components/BackHeader/StyledBackHeader.js | 34 +++++++++++ .../lib/src/components/BackHeader/index.js | 58 +++++++++++-------- 2 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 packages/strapi-helper-plugin/lib/src/components/BackHeader/StyledBackHeader.js diff --git a/packages/strapi-helper-plugin/lib/src/components/BackHeader/StyledBackHeader.js b/packages/strapi-helper-plugin/lib/src/components/BackHeader/StyledBackHeader.js new file mode 100644 index 0000000000..84cef0c23a --- /dev/null +++ b/packages/strapi-helper-plugin/lib/src/components/BackHeader/StyledBackHeader.js @@ -0,0 +1,34 @@ +/* + * + * + * StyledBackHeader + * + */ +import styled from 'styled-components'; + +const StyledBackHeader = styled.div` + position: fixed; + top: 0; + height: 6rem; + width: 6.5rem; + line-height: 6rem; + z-index: 1050; + text-align: center; + background-color: #ffffff; + color: #81848a; + border-top: 1px solid #f3f4f4; + border-right: 1px solid #f3f4f4; + border-left: 1px solid #f3f4f4; + cursor: pointer; + &:before { + content: '\f053'; + font-family: 'FontAwesome'; + font-size: 1.8rem; + font-weight: bolder; + } + &:hover { + background-color: #f3f4f4; + } +`; + +export default StyledBackHeader; diff --git a/packages/strapi-helper-plugin/lib/src/components/BackHeader/index.js b/packages/strapi-helper-plugin/lib/src/components/BackHeader/index.js index b8a1a4226b..32a6673408 100644 --- a/packages/strapi-helper-plugin/lib/src/components/BackHeader/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/BackHeader/index.js @@ -4,31 +4,39 @@ * BackHeader * */ -import styled from 'styled-components'; -const BackHeader = styled.div` - position: fixed; - top: 0; - height: 6rem; - width: 6.5rem; - line-height: 6rem; - z-index: 1050; - text-align: center; - background-color: #ffffff; - color: #81848a; - border-top: 1px solid #f3f4f4; - border-right: 1px solid #f3f4f4; - border-left: 1px solid #f3f4f4; - cursor: pointer; - &:before { - content: '\f053'; - font-family: 'FontAwesome'; - font-size: 1.8rem; - font-weight: bolder; - } - &:hover { - background-color: #f3f4f4; - } -`; +import React from 'react'; +import { get } from 'lodash'; +import { useRouteMatch } from 'react-router-dom'; +import PropTypes from 'prop-types'; +import { useGlobalContext } from '../../contexts/GlobalContext'; +import StyledBackHeader from './StyledBackHeader'; + +const BackHeader = props => { + const { emitEvent } = useGlobalContext(); + const pluginsParams = useRouteMatch('/plugins/:pluginId'); + const settingsParams = useRouteMatch('/settings/:settingType'); + const pluginId = get(pluginsParams, ['params', 'pluginId'], null); + const settingType = get(settingsParams, ['params', 'settingType'], null); + const location = pluginId || settingType; + + const handleClick = e => { + if (location) { + emitEvent('didGoBack', { location }); + } + + props.onClick(e); + }; + + return ; +}; + +BackHeader.defaultProps = { + onClick: () => {}, +}; + +BackHeader.propTypes = { + onClick: PropTypes.func, +}; export default BackHeader;