Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getChildTag fn to Inline component #6453

Merged
merged 4 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/empty-panthers-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Dashboard cards now enclosed in unordered list, for clearer semantics.
5 changes: 5 additions & 0 deletions .changeset/long-birds-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-ui/core': minor
---

Added functionality to ensure that Inline elements that are 'ul' or 'ol' automatically wrap children in 'li' rather than 'div'
7 changes: 4 additions & 3 deletions design-system/packages/core/src/components/Inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Children, ReactNode } from 'react';
import { jsx } from '../emotion';

import { forwardRefWithAs } from '../utils';
import { forwardRefWithAs, getChildTag } from '../utils';
import { Theme } from '../types';
import { useTheme } from '../theme';
import { Box, BoxProps } from './Box';
Expand All @@ -30,6 +30,7 @@ export const Inline = forwardRefWithAs<'div', InlineProps>(
const { spacing } = useTheme();
const resolvedAlign = alignment[align];
const resolvedGap = spacing[gap];
const ChildWrapper = getChildTag(props.as);

return (
<Box
Expand All @@ -45,7 +46,7 @@ export const Inline = forwardRefWithAs<'div', InlineProps>(
>
{Children.map(children, child =>
child !== null && child !== undefined ? (
<div
<ChildWrapper
css={{
display: 'flex',
flexWrap: 'wrap',
Expand All @@ -54,7 +55,7 @@ export const Inline = forwardRefWithAs<'div', InlineProps>(
}}
>
{child}
</div>
</ChildWrapper>
) : null
)}
</Box>
Expand Down
14 changes: 2 additions & 12 deletions design-system/packages/core/src/components/Stack.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/** @jsxRuntime classic */
/** @jsx jsx */

import { ElementType, Children, Fragment, ReactNode, isValidElement } from 'react';
import { Children, Fragment, ReactNode, isValidElement } from 'react';

import { jsx } from '../emotion';
import { useMediaQuery } from '../hooks/useMediaQuery';
import { useTheme } from '../theme';
import { Theme } from '../types';
import { forwardRefWithAs, mapResponsiveProp } from '../utils';
import { forwardRefWithAs, mapResponsiveProp, getChildTag } from '../utils';

import { Box, BoxProps } from './Box';
import { Divider } from './Divider';
Expand Down Expand Up @@ -45,16 +45,6 @@ export type StackProps = {
gap?: keyof Theme['spacing'];
} & BoxProps;

const getChildTag = (parentTag?: ElementType<any>) => {
switch (parentTag) {
case 'ul':
case 'ol':
return 'li';
default:
return 'div';
}
};

export const Stack = forwardRefWithAs<'div', StackProps>(
({ across, align = 'stretch', children, dividers = 'none', gap = 'none', ...props }, ref) => {
const { spacing } = useTheme();
Expand Down
14 changes: 14 additions & 0 deletions design-system/packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ import {
} from 'react';
import { createPortal } from 'react-dom';

/*
Simple switch to return a child tag from a parent tag argument.
Returns a div by default.
*/
export const getChildTag = (parentTag?: ElementType<any>) => {
switch (parentTag) {
case 'ul':
case 'ol':
return 'li';
default:
return 'div';
}
};

/*
@johannes' one weird trick for fixing TypeScript autocomplete
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const ListCard = ({ listKey, count }: ListCardProps) => {
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const router = useRouter();
return (
<div css={{ position: 'relative' }}>
<div
css={{
position: 'relative',
}}
>
<Link
href={`/${list.path}`}
css={{
Expand Down Expand Up @@ -158,7 +162,15 @@ export const HomePage = () => {
<LoadingDots label="Loading lists" size="large" tone="passive" />
</Center>
) : (
<Inline gap="large" paddingY="xlarge">
<Inline
as="ul"
gap="large"
paddingY="xlarge"
css={{
paddingInlineStart: '0px',
gwyneplaine marked this conversation as resolved.
Show resolved Hide resolved
marginBottom: '0px',
}}
>
{(() => {
if (visibleLists.state === 'error') {
return (
Expand Down