@faststore/ui 1.8.46 → 1.8.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/ui",
3
- "version": "1.8.46",
3
+ "version": "1.8.52",
4
4
  "description": "A lightweight, framework agnostic component library for React",
5
5
  "author": "emersonlaurentino",
6
6
  "license": "MIT",
@@ -89,5 +89,5 @@
89
89
  "tsdx": "^0.14.1",
90
90
  "typescript": "^4.2.4"
91
91
  },
92
- "gitHead": "a71780755aebd9d78b51167d7ba6c8ddbeb9c510"
92
+ "gitHead": "3d9c06662ab85ef52c457aa0c7418625e966bf9b"
93
93
  }
package/src/index.ts CHANGED
@@ -187,6 +187,13 @@ export type {
187
187
  OutOfStockTitleProps,
188
188
  } from './organisms/OutOfStock'
189
189
 
190
+ export { default as Hero, HeroHeading, HeroImage } from './organisms/Hero'
191
+ export type {
192
+ HeroProps,
193
+ HeroHeadingProps,
194
+ HeroImageProps,
195
+ } from './organisms/Hero'
196
+
190
197
  // Hooks
191
198
  export { default as useSlider } from './hooks/useSlider'
192
199
  export type {
@@ -0,0 +1,60 @@
1
+ import { render } from '@testing-library/react'
2
+ import { axe } from 'jest-axe'
3
+ import React from 'react'
4
+
5
+ import Hero from './Hero'
6
+ import HeroImage from './HeroImage'
7
+ import HeroHeading from './HeroHeading'
8
+
9
+ const HeroTest = () => {
10
+ return (
11
+ <Hero data-custom-attribute>
12
+ <HeroImage>
13
+ <img
14
+ alt="Quest 2 Controller on a table"
15
+ src="https://storeframework.vtexassets.com/arquivos/ids/190897/Photo.jpg"
16
+ />
17
+ </HeroImage>
18
+ <HeroHeading>
19
+ <h3>Get yo know our next release</h3>
20
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
21
+ <a href="/">Shop Now</a>
22
+ </HeroHeading>
23
+ </Hero>
24
+ )
25
+ }
26
+
27
+ describe('Hero', () => {
28
+ describe('Data attributes', () => {
29
+ const { getByTestId } = render(<HeroTest />)
30
+
31
+ const hero = getByTestId('store-hero')
32
+ const heroImage = getByTestId('store-hero-image')
33
+ const heroHeading = getByTestId('store-hero-heading')
34
+
35
+ it('`Hero` component should have `data-store-hero` attribute', () => {
36
+ expect(hero).toHaveAttribute('data-store-hero')
37
+ })
38
+
39
+ it('`Hero` component should have custom data attribute `data-custom-attribute`', () => {
40
+ expect(hero).toHaveAttribute('data-custom-attribute')
41
+ })
42
+
43
+ it('`HeroImage` component should have `data-hero-image` attribute', () => {
44
+ expect(heroImage).toHaveAttribute('data-hero-image')
45
+ })
46
+
47
+ it('`HeroHeading` component should have `data-hero-heading` attribute', () => {
48
+ expect(heroHeading).toHaveAttribute('data-hero-heading')
49
+ })
50
+ })
51
+
52
+ describe('Accessibility', () => {
53
+ it('should have no violations', async () => {
54
+ const { getByTestId } = render(<HeroTest />)
55
+
56
+ expect(await axe(getByTestId('store-hero'))).toHaveNoViolations()
57
+ expect(await axe(getByTestId('store-hero'))).toHaveNoIncompletes()
58
+ })
59
+ })
60
+ })
@@ -0,0 +1,23 @@
1
+ import React, { forwardRef } from 'react'
2
+ import type { HTMLAttributes } from 'react'
3
+
4
+ export interface HeroProps extends HTMLAttributes<HTMLDivElement> {
5
+ /**
6
+ * ID to find this component in testing tools (e.g.: cypress,
7
+ * testing-library, and jest).
8
+ */
9
+ testId?: string
10
+ }
11
+
12
+ const Hero = forwardRef<HTMLDivElement, HeroProps>(function Hero(
13
+ { testId = 'store-hero', children, ...otherProps },
14
+ ref
15
+ ) {
16
+ return (
17
+ <article ref={ref} data-store-hero data-testid={testId} {...otherProps}>
18
+ {children}
19
+ </article>
20
+ )
21
+ })
22
+
23
+ export default Hero
@@ -0,0 +1,24 @@
1
+ import type { HTMLAttributes } from 'react'
2
+ import React, { forwardRef } from 'react'
3
+
4
+ export interface HeroHeadingProps extends HTMLAttributes<HTMLDivElement> {
5
+ /**
6
+ * ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
7
+ */
8
+ testId?: string
9
+ }
10
+
11
+ const HeroHeading = forwardRef<HTMLDivElement, HeroHeadingProps>(
12
+ function HeroHeading(
13
+ { testId = 'store-hero-heading', children, ...otherProps },
14
+ ref
15
+ ) {
16
+ return (
17
+ <header ref={ref} data-hero-heading data-testid={testId} {...otherProps}>
18
+ {children}
19
+ </header>
20
+ )
21
+ }
22
+ )
23
+
24
+ export default HeroHeading
@@ -0,0 +1,22 @@
1
+ import type { HTMLAttributes } from 'react'
2
+ import React, { forwardRef } from 'react'
3
+
4
+ export interface HeroImageProps extends HTMLAttributes<HTMLDivElement> {
5
+ /**
6
+ * ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
7
+ */
8
+ testId?: string
9
+ }
10
+
11
+ const HeroImage = forwardRef<HTMLDivElement, HeroImageProps>(function HeroImage(
12
+ { testId = 'store-hero-image', children, ...otherProps },
13
+ ref
14
+ ) {
15
+ return (
16
+ <div ref={ref} data-hero-image data-testid={testId} {...otherProps}>
17
+ {children}
18
+ </div>
19
+ )
20
+ })
21
+
22
+ export default HeroImage
@@ -0,0 +1,8 @@
1
+ export { default } from './Hero'
2
+ export type { HeroProps } from './Hero'
3
+
4
+ export { default as HeroImage } from './HeroImage'
5
+ export type { HeroImageProps } from './HeroImage'
6
+
7
+ export { default as HeroHeading } from './HeroHeading'
8
+ export type { HeroHeadingProps } from './HeroHeading'
@@ -0,0 +1,48 @@
1
+ import { Canvas, Props, Story, ArgsTable } from '@storybook/addon-docs'
2
+
3
+ import Hero from '../Hero'
4
+ import HeroImage from '../HeroImage'
5
+ import HeroHeading from '../HeroHeading'
6
+
7
+ # Hero
8
+
9
+ <Canvas>
10
+ <Story id="organisms-hero--hero" />
11
+ </Canvas>
12
+
13
+ ## Components
14
+
15
+ The `Hero` uses the [Compound Component](https://kentcdodds.com/blog/compound-components-with-react-hooks) pattern, its components are:
16
+
17
+ - `Hero`: the wrapper component.
18
+ - `HeroImage`: the component that wraps the image displayed in the component.
19
+ - `HeroHeading`: the component should have a title, description, and a call to action link.
20
+
21
+ ## Props
22
+
23
+ All hero-related components support all attributes also supported by the `<div>` tag.
24
+
25
+ Besides those attributes, the following props are also supported:
26
+
27
+ ### `Hero`
28
+
29
+ <ArgsTable of={Hero} />
30
+
31
+ ### `HeroImage`
32
+
33
+ <ArgsTable of={HeroImage} />
34
+
35
+ ### `HeroHeading`
36
+
37
+ <ArgsTable of={HeroHeading} />
38
+
39
+ ## CSS Selectors
40
+
41
+ ```css
42
+ [data-store-hero] {
43
+ }
44
+ [data-hero-image] {
45
+ }
46
+ [data-hero-heading] {
47
+ }
48
+ ```
@@ -0,0 +1,56 @@
1
+ import type { Story, Meta } from '@storybook/react'
2
+ import React from 'react'
3
+
4
+ import HeroComponent from '../Hero'
5
+ import HeroImage from '../HeroImage'
6
+ import HeroHeading from '../HeroHeading'
7
+ import type { HeroProps } from '../Hero'
8
+ import { Icon } from '../../..'
9
+ import mdx from './Hero.mdx'
10
+
11
+ const RightArrow = () => (
12
+ <svg
13
+ xmlns="http://www.w3.org/2000/svg"
14
+ width="18"
15
+ height="18"
16
+ viewBox="0 0 18 18"
17
+ >
18
+ <path
19
+ d="M10.6553 3.40717C10.3624 3.11428 9.88756 3.11428 9.59467 3.40717C9.30178 3.70006 9.30178 4.17494 9.59467 4.46783L13.3768 8.25H2.8125C2.39829 8.25 2.0625 8.58579 2.0625 9C2.0625 9.41421 2.39829 9.75 2.8125 9.75H13.3768L9.59467 13.5322C9.30178 13.8251 9.30178 14.2999 9.59467 14.5928C9.88756 14.8857 10.3624 14.8857 10.6553 14.5928L15.7178 9.53033C15.8643 9.38388 15.9375 9.19194 15.9375 9C15.9375 8.89831 15.9173 8.80134 15.8806 8.71291C15.844 8.62445 15.7897 8.54158 15.7178 8.46967L10.6553 3.40717Z"
20
+ fill="currentColor"
21
+ />
22
+ </svg>
23
+ )
24
+
25
+ const HeroTemplate: Story<HeroProps> = ({ testId }) => (
26
+ <HeroComponent testId={testId}>
27
+ <HeroImage>
28
+ <img
29
+ alt="Quest 2 Controller on a table"
30
+ src="https://storeframework.vtexassets.com/arquivos/ids/190897/Photo.jpg"
31
+ />
32
+ </HeroImage>
33
+ <HeroHeading>
34
+ <h1>New Products Available</h1>
35
+ <p>
36
+ At BaseStore you can shop the best tech of 2022. Enjoy and get 10% off
37
+ on your first purchase.
38
+ </p>
39
+ <a href="/">
40
+ See all <Icon component={<RightArrow />} />
41
+ </a>
42
+ </HeroHeading>
43
+ </HeroComponent>
44
+ )
45
+
46
+ export const Hero = HeroTemplate.bind({})
47
+ Hero.storyName = 'Hero'
48
+
49
+ export default {
50
+ title: 'Organisms/Hero',
51
+ parameters: {
52
+ docs: {
53
+ page: mdx,
54
+ },
55
+ },
56
+ } as Meta
@@ -13,9 +13,14 @@ export const OutOfStockMessage = ({
13
13
  as: MessageComponent = 'p',
14
14
  testId = 'store-out-of-stock-message',
15
15
  children,
16
+ ...otherProps
16
17
  }: OutOfStockMessageProps) => {
17
18
  return (
18
- <MessageComponent data-out-of-stock-message data-testid={testId}>
19
+ <MessageComponent
20
+ data-out-of-stock-message
21
+ data-testid={testId}
22
+ {...otherProps}
23
+ >
19
24
  {children}
20
25
  </MessageComponent>
21
26
  )
@@ -13,9 +13,14 @@ export const OutOfStockTitle = ({
13
13
  as: TitleComponent = 'h2',
14
14
  testId = 'store-out-of-stock-title',
15
15
  children,
16
+ ...otherProps
16
17
  }: OutOfStockTitleProps) => {
17
18
  return (
18
- <TitleComponent data-out-of-stock-title data-testid={testId}>
19
+ <TitleComponent
20
+ data-out-of-stock-title
21
+ data-testid={testId}
22
+ {...otherProps}
23
+ >
19
24
  {children}
20
25
  </TitleComponent>
21
26
  )