contentbox + fixed title ellipsis

This commit is contained in:
ronronscelestes 2021-11-09 16:00:03 +01:00
parent 5e9a00a51f
commit d1f29f033b
6 changed files with 13 additions and 39 deletions

View File

@ -44,6 +44,7 @@ const MagicLinkWrapper = ({ children, target }) => {
</CopyToClipboard> </CopyToClipboard>
} }
title={target} title={target}
titleEllipsis
subtitle={children} subtitle={children}
icon={<Envelope />} icon={<Envelope />}
iconBackground="neutral100" iconBackground="neutral100"

View File

@ -47,6 +47,7 @@ TODO
iconBackground="alternative100" iconBackground="alternative100"
/> />
<ContentBox <ContentBox
titleEllipsis
endAction={<IconButton label="Duplicate" noBorder icon={<Duplicate />} />} endAction={<IconButton label="Duplicate" noBorder icon={<Duplicate />} />}
title="http://localhost:4000/admin/auth/register?registrationToken=e02849fabef5239fe3c459d23d8c3b30d5057aa9" title="http://localhost:4000/admin/auth/register?registrationToken=e02849fabef5239fe3c459d23d8c3b30d5057aa9"
subtitle="Send this link to the user for them to connect" subtitle="Send this link to the user for them to connect"

View File

@ -4,7 +4,7 @@ import styled from 'styled-components';
import { Flex } from '@strapi/design-system/Flex'; import { Flex } from '@strapi/design-system/Flex';
import { Stack } from '@strapi/design-system/Stack'; import { Stack } from '@strapi/design-system/Stack';
import { Text } from '@strapi/design-system/Text'; import { Text } from '@strapi/design-system/Text';
import customEllipsis from '../../utils/customEllipsis'; import { Typography } from '@strapi/design-system/Typography';
const IconWrapper = styled(Flex)` const IconWrapper = styled(Flex)`
margin-right: ${({ theme }) => theme.spaces[6]}; margin-right: ${({ theme }) => theme.spaces[6]};
@ -14,11 +14,13 @@ const IconWrapper = styled(Flex)`
} }
`; `;
const ContentBox = ({ title, subtitle, icon, iconBackground, endAction }) => { const TypographyWordBreak = styled(Typography)`
const firstTitleChar = title.substring(0, 4); word-break: break-all;
`;
if (title.length > 70 && firstTitleChar === 'http') { const ContentBox = ({ title, subtitle, icon, iconBackground, endAction, titleEllipsis }) => {
title = customEllipsis(title); if (title.length > 70 && titleEllipsis) {
title = `${title.substring(0, 70)}...`;
} }
return ( return (
@ -28,9 +30,9 @@ const ContentBox = ({ title, subtitle, icon, iconBackground, endAction }) => {
</IconWrapper> </IconWrapper>
<Stack size={endAction ? 0 : 1}> <Stack size={endAction ? 0 : 1}>
<Flex> <Flex>
<Text small bold style={{ wordBreak: 'break-all' }}> <TypographyWordBreak variant="pi" fontWeight="bold">
{title} {title}
</Text> </TypographyWordBreak>
{endAction} {endAction}
</Flex> </Flex>
<Text textColor="neutral600">{subtitle}</Text> <Text textColor="neutral600">{subtitle}</Text>
@ -40,6 +42,7 @@ const ContentBox = ({ title, subtitle, icon, iconBackground, endAction }) => {
}; };
ContentBox.defaultProps = { ContentBox.defaultProps = {
titleEllipsis: false,
title: undefined, title: undefined,
subtitle: undefined, subtitle: undefined,
icon: undefined, icon: undefined,
@ -48,6 +51,7 @@ ContentBox.defaultProps = {
}; };
ContentBox.propTypes = { ContentBox.propTypes = {
titleEllipsis: PropTypes.bool,
title: PropTypes.string, title: PropTypes.string,
subtitle: PropTypes.string, subtitle: PropTypes.string,
icon: PropTypes.node, icon: PropTypes.node,

View File

@ -88,7 +88,6 @@ export { default as prefixPluginTranslations } from './utils/prefixPluginTransla
export { default as pxToRem } from './utils/pxToRem'; export { default as pxToRem } from './utils/pxToRem';
export { default as to } from './utils/await-to-js'; export { default as to } from './utils/await-to-js';
export { default as setHexOpacity } from './utils/setHexOpacity'; export { default as setHexOpacity } from './utils/setHexOpacity';
export { default as customEllipsis } from './utils/customEllipsis';
export { default as translatedErrors } from './utils/translatedErrors'; export { default as translatedErrors } from './utils/translatedErrors';
export { default as formatComponentData } from './content-manager/utils/formatComponentData'; export { default as formatComponentData } from './content-manager/utils/formatComponentData';
export { findMatchingPermissions } from './utils/hasPermissions'; export { findMatchingPermissions } from './utils/hasPermissions';

View File

@ -1,25 +0,0 @@
<!--- customEllipsis.stories.mdx --->
import { Meta } from '@storybook/addon-docs';
<Meta title="utils/customEllipsis" />
# customEllipsis
This hook is used to have a custom ellipsis for large url
## Usage
```js
import { customEllipsis } from '@strapi/helper-plugin';
const ContentBox = ({ title, subtitle, icon, iconBackground, endAction }) => {
const firstTitleChar = title.substring(0, 4);
if (title.length > 70 && firstTitleChar === 'http') {
//will return for example http://localhost:4000/admin/auth/register?registrationToken=e0...aa9
title = customEllipsis(title);
}
return <div>title</div>;
```

View File

@ -1,6 +0,0 @@
const customEllipsis = title => {
const endSubstring = title.indexOf('registrationToken') + 20;
return `${title.substring(0, endSubstring)}...${title.substring(title.length - 3, title.length)}`;
};
export default customEllipsis;