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

308: Add skeleton loading component #378

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
Empty file added src/ebay-skeleton/README.md
Empty file.
39 changes: 39 additions & 0 deletions src/ebay-skeleton/__tests__/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react'
import { EbaySkeleton, EbaySkeletonAvatar, EbaySkeletonButton, EbaySkeletonImage } from '../'

export default {
component: EbaySkeleton,
title: 'skeleton &ebay-skeleton-avatar'
}

export const Avatar = () => (
<>
<EbaySkeleton>
<EbaySkeletonAvatar />
</EbaySkeleton>
</>
)

export const ButtonSmall = () => (
<>
<EbaySkeleton>
<EbaySkeletonButton size="small" style={{ width: '200px'}} />
</EbaySkeleton>
</>
)

export const ButtonLarge = () => (
<>
<EbaySkeleton>
<EbaySkeletonButton size="large" style={{ width: '200px'}}/>
</EbaySkeleton>
</>
)

export const Image = () => (
<>
<EbaySkeleton>
<EbaySkeletonImage style={{ width: '100px', height: '100px' }} />
</EbaySkeleton>
</>
)
21 changes: 21 additions & 0 deletions src/ebay-skeleton/ebay-skeleton-avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { ComponentProps, FC } from 'react'

Check warning

Code scanning / ESLint

Disallow unused variables Warning

'ComponentProps' is defined but never used.

Copilot Autofix AI 22 days ago

To fix the problem, we need to remove the unused import ComponentProps from the import statement on line 1. This will resolve the ESLint error and clean up the code by removing unnecessary imports.

Suggested changeset 1
src/ebay-skeleton/ebay-skeleton-avatar.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/ebay-skeleton/ebay-skeleton-avatar.tsx b/src/ebay-skeleton/ebay-skeleton-avatar.tsx
--- a/src/ebay-skeleton/ebay-skeleton-avatar.tsx
+++ b/src/ebay-skeleton/ebay-skeleton-avatar.tsx
@@ -1,2 +1,2 @@
-import React, { ComponentProps, FC } from 'react'
+import React, { FC } from 'react'
 import classNames from 'classnames'
EOF
@@ -1,2 +1,2 @@
import React, { ComponentProps, FC } from 'react'
import React, { FC } from 'react'
import classNames from 'classnames'
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like valid concern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint should have got this, we need to understand why not

import classNames from 'classnames'
import { NativeTags } from './nativeTags'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the react type instead:

    as?: keyof React.JSX.IntrinsicElements;

But I think skin supports div and span only


export type Props = {
as?: NativeTags,
className?: string
}

const EbaySkeletonAvatar: FC<Props> = ({
as = 'div',
className,
...rest
}) => {
const NativeTag = as
return (
<NativeTag className={classNames('skeleton__avatar', className)} {...rest} />
)
}

export default EbaySkeletonAvatar
22 changes: 22 additions & 0 deletions src/ebay-skeleton/ebay-skeleton-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { ComponentProps, FC } from 'react'
import classNames from 'classnames'

export type Props = ComponentProps<'div'> & {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[trivial] other components are exporting types in a separate file

size?: 'small' | 'large';
}

const EbaySkeletonButton: FC<Props> = ({
size,
className,
...rest
}) => (
<div
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to support the as also

className={classNames(
'skeleton__button',
size ? `skeleton__button--${size}` : '',
className)}
{...rest}
/>
)

export default EbaySkeletonButton
18 changes: 18 additions & 0 deletions src/ebay-skeleton/ebay-skeleton-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { ComponentProps, FC } from 'react'
import classNames from 'classnames'

export type Props = ComponentProps<'div'> & {
a11yText?: string;
}

const EbaySkeletonImage: FC<Props> = ({
className,
...rest
}) => (
<div
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to support as also

className={classNames('skeleton__image', className)}
{...rest}
/>
)

export default EbaySkeletonImage
26 changes: 26 additions & 0 deletions src/ebay-skeleton/ebay-skeleton-text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { ComponentProps, FC } from 'react'
import classNames from 'classnames'

export type Props = ComponentProps<'div'> & {
size?: 'small' | 'large';
multiline?: boolean;
}

const EbaySkeletonText: FC<Props> = ({
className,
size,
multiline,
...rest
}) => (
<div
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to support as also

className={classNames(
'skeleton__text',
multiline && 'skeleton__text--multiline',
size === 'large' && `skeleton__text--large`,
className
)}
{...rest}
/>
)

export default EbaySkeletonText
16 changes: 16 additions & 0 deletions src/ebay-skeleton/ebay-skeleton-textbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { ComponentProps, FC } from 'react'
import classNames from 'classnames'

export type Props = ComponentProps<'div'>

const EbaySkeletonText: FC<Props> = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be EbaySkeletonTextbox?

className,
...rest
}) => (
<div
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to support as also

className={classNames('skeleton__textbox', className)}
{...rest}
/>
)

export default EbaySkeletonText
24 changes: 24 additions & 0 deletions src/ebay-skeleton/ebay-skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { ComponentProps, FC } from 'react'
import classNames from 'classnames'

export type Props = ComponentProps<'div'> & {
a11yText?: string;
}

const EbaySkeleton: FC<Props> = ({
children,
a11yText = 'Loading...',
className,
...rest
}) => (
<div
role="img"
aria-label={a11yText}
className={classNames('skeleton', className)}
{...rest}
>
{children}
</div>
)

export default EbaySkeleton
6 changes: 6 additions & 0 deletions src/ebay-skeleton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { default as EbaySkeleton } from './ebay-skeleton'
export { default as EbaySkeletonAvatar } from './ebay-skeleton-avatar'
export { default as EbaySkeletonButton } from './ebay-skeleton-button'
export { default as EbaySkeletonImage } from './ebay-skeleton-image'
export { default as EbaySkeletonText } from './ebay-skeleton-text'
export { default as EbaySkeletonTextbox } from './ebay-skeleton-textbox'
112 changes: 112 additions & 0 deletions src/ebay-skeleton/nativeTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
export type NativeTags =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is based on Marko.NativeTags

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React has keyof React.JSX.IntrinsicElements, we should use that instead. But I think skin supports div and span only as per documentation

'a' |
'abbr' |
'address' |
'area' |
'article' |
'aside' |
'audio' |
'b' |
'base' |
'bdi' |
'bdo' |
'blockquote' |
'body' |
'br' |
'button' |
'canvas' |
'caption' |
'cite' |
'code' |
'col' |
'colgroup' |
'data' |
'datalist' |
'dd' |
'del' |
'details' |
'dfn' |
'dialog' |
'div' |
'dl' |
'dt' |
'em' |
'embed' |
'fieldset' |
'figcaption' |
'figure' |
'footer' |
'form' |
'h1' |
'h2' |
'h3' |
'h4' |
'h5' |
'h6' |
'head' |
'header' |
'hgroup' |
'hr' |
'html' |
'i' |
'iframe' |
'img' |
'input' |
'ins' |
'kbd' |
'label' |
'legend' |
'li' |
'link' |
'main' |
'map' |
'mark' |
'menu' |
'meta' |
'meter' |
'nav' |
'noscript' |
'object' |
'ol' |
'optgroup' |
'option' |
'output' |
'p' |
'picture' |
'pre' |
'progress' |
'q' |
'rp' |
'rt' |
'ruby' |
's' |
'samp' |
'script' |
'section' |
'select' |
'slot' |
'small' |
'source' |
'span' |
'strong' |
'style' |
'sub' |
'summary' |
'sup' |
'table' |
'tbody' |
'td' |
'template' |
'textarea' |
'tfoot' |
'th' |
'thead' |
'time' |
'title' |
'tr' |
'track' |
'u' |
'ul' |
'var' |
'video' |
'wbr'
Loading