mirror of
https://github.com/strapi/strapi.git
synced 2025-11-11 07:39:16 +00:00
loadingMessage prop, label structure + loading style improvements
This commit is contained in:
parent
be5c3d23d6
commit
62c50bedfb
@ -9,6 +9,7 @@ import { BaseLink } from '@strapi/design-system/BaseLink';
|
|||||||
import { Icon } from '@strapi/design-system/Icon';
|
import { Icon } from '@strapi/design-system/Icon';
|
||||||
import { FieldLabel, FieldError, FieldHint, Field } from '@strapi/design-system/Field';
|
import { FieldLabel, FieldError, FieldHint, Field } from '@strapi/design-system/Field';
|
||||||
import { TextButton } from '@strapi/design-system/TextButton';
|
import { TextButton } from '@strapi/design-system/TextButton';
|
||||||
|
import { Typography } from '@strapi/design-system/Typography';
|
||||||
import { Loader } from '@strapi/design-system/Loader';
|
import { Loader } from '@strapi/design-system/Loader';
|
||||||
|
|
||||||
import Cross from '@strapi/icons/Cross';
|
import Cross from '@strapi/icons/Cross';
|
||||||
@ -21,10 +22,10 @@ import { Option } from './components/Option';
|
|||||||
|
|
||||||
import ReactSelect from '../ReactSelect';
|
import ReactSelect from '../ReactSelect';
|
||||||
|
|
||||||
const BoxEllipsis = styled(Box)`
|
const RelationItemCenterChildren = styled(RelationItem)`
|
||||||
white-space: nowrap;
|
div {
|
||||||
overflow: hidden;
|
justify-content: center;
|
||||||
text-overflow: ellipsis;
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const RelationInput = ({
|
export const RelationInput = ({
|
||||||
@ -36,6 +37,7 @@ export const RelationInput = ({
|
|||||||
label,
|
label,
|
||||||
labelLoadMore,
|
labelLoadMore,
|
||||||
listHeight,
|
listHeight,
|
||||||
|
loadingMessage,
|
||||||
relations,
|
relations,
|
||||||
onRelationClose,
|
onRelationClose,
|
||||||
onRelationAdd,
|
onRelationAdd,
|
||||||
@ -65,13 +67,7 @@ export const RelationInput = ({
|
|||||||
inputId={id}
|
inputId={id}
|
||||||
isSearchable
|
isSearchable
|
||||||
isClear
|
isClear
|
||||||
loadingMessage={() =>
|
loadingMessage={() => <Loader small>{formatMessage(loadingMessage)}</Loader>}
|
||||||
// To fix: use getTrad utils from CM once component is migrated into CM components
|
|
||||||
formatMessage({
|
|
||||||
id: 'content-manager.DynamicTable.relation-search-loading',
|
|
||||||
defaultMessage: 'Entries are loading',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
onChange={onRelationAdd}
|
onChange={onRelationAdd}
|
||||||
onInputChange={onSearch}
|
onInputChange={onSearch}
|
||||||
onMenuClose={onRelationOpen}
|
onMenuClose={onRelationOpen}
|
||||||
@ -109,15 +105,19 @@ export const RelationInput = ({
|
|||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<BoxEllipsis paddingTop={1} paddingBottom={1} paddingRight={4}>
|
<Box minWidth={0} paddingTop={1} paddingBottom={1} paddingRight={4}>
|
||||||
{href ? (
|
{href ? (
|
||||||
<BaseLink disabled={disabled} href={href}>
|
<BaseLink disabled={disabled} href={href}>
|
||||||
|
<Typography textColor={disabled ? 'neutral600' : 'primary600'} ellipsis>
|
||||||
{mainField}
|
{mainField}
|
||||||
|
</Typography>
|
||||||
</BaseLink>
|
</BaseLink>
|
||||||
) : (
|
) : (
|
||||||
mainField
|
<Typography textColor={disabled ? 'neutral600' : 'primary600'} ellipsis>
|
||||||
|
{mainField}
|
||||||
|
</Typography>
|
||||||
)}
|
)}
|
||||||
</BoxEllipsis>
|
</Box>
|
||||||
|
|
||||||
{publicationState && (
|
{publicationState && (
|
||||||
<Badge
|
<Badge
|
||||||
@ -134,14 +134,9 @@ export const RelationInput = ({
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{relations.isLoading && (
|
{relations.isLoading && (
|
||||||
<RelationItem>
|
<RelationItemCenterChildren>
|
||||||
<Loader small>
|
<Loader small>{formatMessage(loadingMessage)}</Loader>
|
||||||
{formatMessage({
|
</RelationItemCenterChildren>
|
||||||
id: 'content-manager.DynamicTable.relation-loading',
|
|
||||||
defaultMessage: 'Relations are loading',
|
|
||||||
})}
|
|
||||||
</Loader>
|
|
||||||
</RelationItem>
|
|
||||||
)}
|
)}
|
||||||
</RelationList>
|
</RelationList>
|
||||||
<Box paddingTop={2}>
|
<Box paddingTop={2}>
|
||||||
@ -203,6 +198,10 @@ RelationInput.propTypes = {
|
|||||||
label: PropTypes.string.isRequired,
|
label: PropTypes.string.isRequired,
|
||||||
labelLoadMore: PropTypes.string.isRequired,
|
labelLoadMore: PropTypes.string.isRequired,
|
||||||
listHeight: PropTypes.string,
|
listHeight: PropTypes.string,
|
||||||
|
loadingMessage: PropTypes.shape({
|
||||||
|
id: PropTypes.string,
|
||||||
|
defaultMessage: PropTypes.string,
|
||||||
|
}).isRequired,
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
onRelationAdd: PropTypes.func.isRequired,
|
onRelationAdd: PropTypes.func.isRequired,
|
||||||
onRelationOpen: PropTypes.func.isRequired,
|
onRelationOpen: PropTypes.func.isRequired,
|
||||||
|
|||||||
@ -25,6 +25,7 @@ WIP
|
|||||||
label="Relations"
|
label="Relations"
|
||||||
labelLoadMore="Load More"
|
labelLoadMore="Load More"
|
||||||
listHeight="200px"
|
listHeight="200px"
|
||||||
|
loadingMessage={{ id: 'translation-key', defaultMessage: 'Relations are loading' }}
|
||||||
name="options"
|
name="options"
|
||||||
publicationStateTranslations={{ draft: 'Draft', published: 'Published' }}
|
publicationStateTranslations={{ draft: 'Draft', published: 'Published' }}
|
||||||
searchResults={{
|
searchResults={{
|
||||||
@ -59,13 +60,15 @@ WIP
|
|||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
href: '/',
|
href: '/',
|
||||||
mainField: 'Relation 1 with a very very very very very very very very very very very very very very very very very very very super huge really really long title',
|
mainField:
|
||||||
|
'Relation 1 with a very very very very very very very very very very very very very very very very very very very super huge really really long title',
|
||||||
publicationState: 'draft',
|
publicationState: 'draft',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
href: '',
|
href: '',
|
||||||
mainField: 'Relation 2 with a very very very very very very very very very very very very very very very very very very very super huge really really long title',
|
mainField:
|
||||||
|
'Relation 2 with a very very very very very very very very very very very very very very very very very very very super huge really really long title',
|
||||||
publicationState: 'published',
|
publicationState: 'published',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -89,7 +92,7 @@ WIP
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
isLoading: true,
|
isLoading: false,
|
||||||
isSuccess: true,
|
isSuccess: true,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -3,21 +3,13 @@ import PropTypes from 'prop-types';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Box } from '@strapi/design-system/Box';
|
import { Box } from '@strapi/design-system/Box';
|
||||||
import { Flex } from '@strapi/design-system/Flex';
|
import { Flex } from '@strapi/design-system/Flex';
|
||||||
import { Typography } from '@strapi/design-system/Typography';
|
|
||||||
|
|
||||||
const TypographyWrapper = styled(Typography)`
|
const ChildrenWrapper = styled(Flex)`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
// Used to prevent endAction to be pushed out of container
|
// Used to prevent endAction to be pushed out of container
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ChildrenWrapper = styled(Flex)`
|
|
||||||
div > a {
|
|
||||||
color: currentColor;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const RelationItem = ({ children, disabled, endAction, ...props }) => {
|
export const RelationItem = ({ children, disabled, endAction, ...props }) => {
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
@ -33,11 +25,7 @@ export const RelationItem = ({ children, disabled, endAction, ...props }) => {
|
|||||||
as="li"
|
as="li"
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<TypographyWrapper textColor={disabled ? 'neutral600' : 'primary600'} as="div">
|
<ChildrenWrapper justifyContent="space-between">{children}</ChildrenWrapper>
|
||||||
<ChildrenWrapper justifyContent="space-between" color="currentColor">
|
|
||||||
{children}
|
|
||||||
</ChildrenWrapper>
|
|
||||||
</TypographyWrapper>
|
|
||||||
{endAction && <Box paddingLeft={4}>{endAction}</Box>}
|
{endAction && <Box paddingLeft={4}>{endAction}</Box>}
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`RelationItem should render and match snapshot 1`] = `
|
exports[`RelationItem should render and match snapshot 1`] = `
|
||||||
.c6 {
|
.c3 {
|
||||||
border: 0;
|
border: 0;
|
||||||
-webkit-clip: rect(0 0 0 0);
|
-webkit-clip: rect(0 0 0 0);
|
||||||
clip: rect(0 0 0 0);
|
clip: rect(0 0 0 0);
|
||||||
@ -24,10 +24,6 @@ exports[`RelationItem should render and match snapshot 1`] = `
|
|||||||
border: 1px solid #dcdce4;
|
border: 1px solid #dcdce4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c4 {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c1 {
|
.c1 {
|
||||||
-webkit-align-items: center;
|
-webkit-align-items: center;
|
||||||
-webkit-box-align: center;
|
-webkit-box-align: center;
|
||||||
@ -47,19 +43,8 @@ exports[`RelationItem should render and match snapshot 1`] = `
|
|||||||
}
|
}
|
||||||
|
|
||||||
.c2 {
|
.c2 {
|
||||||
color: #4945ff;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
line-height: 1.43;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c3 {
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
min-width: 0;
|
||||||
|
|
||||||
.c5 div > a {
|
|
||||||
color: currentColor;
|
|
||||||
-webkit-text-decoration: none;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@ -67,18 +52,13 @@ exports[`RelationItem should render and match snapshot 1`] = `
|
|||||||
class="c0 c1"
|
class="c0 c1"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="c2 c3"
|
class="c1 c2"
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="c4 c1 c5"
|
|
||||||
width="100%"
|
|
||||||
>
|
>
|
||||||
First relation
|
First relation
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</li>
|
</li>
|
||||||
<div
|
<div
|
||||||
class="c6"
|
class="c3"
|
||||||
>
|
>
|
||||||
<p
|
<p
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`RelationList should render and match snapshot 1`] = `
|
exports[`RelationList should render and match snapshot 1`] = `
|
||||||
.c9 {
|
.c6 {
|
||||||
border: 0;
|
border: 0;
|
||||||
-webkit-clip: rect(0 0 0 0);
|
-webkit-clip: rect(0 0 0 0);
|
||||||
clip: rect(0 0 0 0);
|
clip: rect(0 0 0 0);
|
||||||
@ -24,10 +24,6 @@ exports[`RelationList should render and match snapshot 1`] = `
|
|||||||
border: 1px solid #dcdce4;
|
border: 1px solid #dcdce4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c7 {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c4 {
|
.c4 {
|
||||||
-webkit-align-items: center;
|
-webkit-align-items: center;
|
||||||
-webkit-box-align: center;
|
-webkit-box-align: center;
|
||||||
@ -47,19 +43,8 @@ exports[`RelationList should render and match snapshot 1`] = `
|
|||||||
}
|
}
|
||||||
|
|
||||||
.c5 {
|
.c5 {
|
||||||
color: #4945ff;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
line-height: 1.43;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c6 {
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
min-width: 0;
|
||||||
|
|
||||||
.c8 div > a {
|
|
||||||
color: currentColor;
|
|
||||||
-webkit-text-decoration: none;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.c1 {
|
.c1 {
|
||||||
@ -121,20 +106,15 @@ exports[`RelationList should render and match snapshot 1`] = `
|
|||||||
class="c3 c4"
|
class="c3 c4"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="c5 c6"
|
class="c4 c5"
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="c7 c4 c8"
|
|
||||||
width="100%"
|
|
||||||
>
|
>
|
||||||
First relation
|
First relation
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="c9"
|
class="c6"
|
||||||
>
|
>
|
||||||
<p
|
<p
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user