@redocly/theme-experimental 0.21.0-next.9 → 0.21.1

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.
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import type { JSX } from 'react';
5
+ import type { ResolvedNavItem } from '@redocly/config';
6
+
7
+ import { Link } from '@redocly/theme/components/Link/Link';
8
+ import { H3 } from '@redocly/theme/components/Typography/H3';
9
+ import { useThemeHooks } from '@redocly/theme/core/hooks';
10
+
11
+ export interface CardProps {
12
+ title?: string;
13
+ icon?: string;
14
+ links: ResolvedNavItem;
15
+ className?: string;
16
+ }
17
+
18
+ export function Card(props: CardProps): JSX.Element {
19
+ const { useTranslate } = useThemeHooks();
20
+ const { translate } = useTranslate();
21
+ return (
22
+ <CardWrapper data-component-name="Cards/Card" className={props.className}>
23
+ {props.icon && <img src={props?.icon} alt={props?.title} />}
24
+ {props.title && <H3>{props.title}</H3>}
25
+ {props.links.items && (
26
+ <CardLinksList>
27
+ {props.links.items.map((item) => (
28
+ <li key={item.label}>
29
+ <Link to={item.link as string}>
30
+ {translate(item.labelTranslationKey, item.label)}
31
+ </Link>
32
+ </li>
33
+ ))}
34
+ </CardLinksList>
35
+ )}
36
+ </CardWrapper>
37
+ );
38
+ }
39
+
40
+ const CardWrapper = styled.div`
41
+ border-radius: 10px;
42
+ box-shadow: 0 10px 30px 0 rgba(35, 35, 35, 0.1);
43
+ padding: 20px;
44
+ margin: 0 20px 20px 0;
45
+ min-width: 25%;
46
+ font-family: var(--font-family-base);
47
+ `;
48
+
49
+ const CardLinksList = styled.ul`
50
+ list-style-type: none;
51
+ margin: 0;
52
+ padding: 0;
53
+
54
+ li {
55
+ margin-bottom: 10px;
56
+ }
57
+ `;
@@ -0,0 +1,10 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const CardsBlock = styled.div.attrs<{ className?: string }>(({ className }) => ({
4
+ 'data-component-name': 'Cards/CardsBlock',
5
+ className,
6
+ }))`
7
+ display: flex;
8
+ padding: 20px 0;
9
+ justify-content: space-between;
10
+ `;
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+
3
+ import { describe, it, expect, vi } from 'vitest';
4
+
5
+ import { Card } from '../Card';
6
+ import { renderWithRouter } from '../../../tests/utils';
7
+
8
+ vi.mock('@redocly/theme/hooks/useThemeHooks');
9
+
10
+ const links = {
11
+ type: 'group' as const,
12
+ label: 'Card Links',
13
+ items: [
14
+ {
15
+ type: 'link' as const,
16
+ link: '#1',
17
+ label: 'Link 1',
18
+ },
19
+ {
20
+ type: 'link' as const,
21
+ link: '#2',
22
+ label: 'Link 2',
23
+ },
24
+ ],
25
+ };
26
+
27
+ describe('Card', () => {
28
+ const props = {
29
+ title: 'Example Card',
30
+ icon: 'example.png',
31
+ links,
32
+ };
33
+
34
+ it('renders', () => {
35
+ const { container } = renderWithRouter(<Card title="Card Links" links={links} />);
36
+
37
+ expect(container.firstChild).toMatchSnapshot();
38
+ });
39
+
40
+ it('renders the title when provided', () => {
41
+ const screen = renderWithRouter(<Card {...props} />);
42
+ const titleElement = screen.getByText('Example Card');
43
+ expect(titleElement).toBeTruthy();
44
+ });
45
+
46
+ it('renders the icon when provided', () => {
47
+ const screen = renderWithRouter(<Card {...props} />);
48
+ const iconElement = screen.getByAltText('Example Card');
49
+ expect(iconElement).toBeTruthy();
50
+ expect(iconElement.getAttribute('src')).toBe('example.png');
51
+ });
52
+
53
+ it('renders the links when provided', () => {
54
+ const screen = renderWithRouter(<Card {...props} />);
55
+ const link1Element = screen.getByText('Link 1');
56
+ const link2Element = screen.getByText('Link 2');
57
+ expect(link1Element).toBeTruthy();
58
+ expect(link2Element).toBeTruthy();
59
+ expect(link1Element.getAttribute('href')).toBe('/#1');
60
+ expect(link2Element.getAttribute('href')).toBe('/#2');
61
+ });
62
+
63
+ it('does not render the title when not provided', () => {
64
+ const { container } = renderWithRouter(<Card links={props.links} />);
65
+ expect(container.querySelector('h3')).toBeNull();
66
+ });
67
+
68
+ it('does not render the icon when not provided', () => {
69
+ const { container } = renderWithRouter(<Card title={props.title} links={props.links} />);
70
+ expect(container.querySelector('img')).toBeNull();
71
+ });
72
+ });
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import { describe, it, expect } from 'vitest';
4
+
5
+ import { CardsBlock } from '../CardsBlock';
6
+
7
+ describe('CardsBlock', () => {
8
+ it('renders', () => {
9
+ const { container } = render(<CardsBlock></CardsBlock>);
10
+
11
+ expect(container.firstChild).toMatchSnapshot();
12
+ });
13
+ });
@@ -0,0 +1,2 @@
1
+ export * from './Card';
2
+ export * from './CardsBlock';
@@ -0,0 +1 @@
1
+ export * from './Cards/index';
@@ -0,0 +1,16 @@
1
+ import type { Schema } from '@markdoc/markdoc';
2
+
3
+ export const card: Schema = {
4
+ attributes: {
5
+ title: { type: String, required: false },
6
+ icon: { type: String, required: false },
7
+ links: { type: String },
8
+ },
9
+ selfClosing: true,
10
+ render: 'Card',
11
+ };
12
+
13
+ export const cardsBlock: Schema = {
14
+ attributes: {},
15
+ render: 'CardsBlock',
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme-experimental",
3
- "version": "0.21.0-next.9",
3
+ "version": "0.21.1",
4
4
  "description": "Experimental UI components lib",
5
5
  "keywords": [
6
6
  "theme-experimental",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@redocly/config": "0.65.0",
52
- "@redocly/theme": "0.70.0-next.9"
52
+ "@redocly/theme": "0.70.1"
53
53
  },
54
54
  "nx": {
55
55
  "targets": {
@@ -1,103 +0,0 @@
1
- # @redocly/theme-experimental
2
-
3
- ⚠️ **This internal readme was copied from the [`@redocly/theme`](../theme/README_INTERNAL.md) package
4
- and slightly modified to be used for the current package.**
5
-
6
- Shared UI components for
7
-
8
- - [@redocly/reference-docs](https://github.com/Redocly/reference-docs),
9
- - [@redocly/graphql-reference-docs](https://github.com/Redocly/graphql-reference-docs)
10
- - New [developer portal](https://github.com/Redocly/redocly/tree/main/packages/portal) and their themes (
11
- e.g. [Portal Default Theme](https://github.com/Redocly/portal-default-theme)).
12
-
13
- # Development
14
-
15
- ## Local development & integration with other packages
16
-
17
- To develop/test your components in other packages (e.g. `reference-docs`) you can use two flows:
18
-
19
- ### 1. Use `copy-and-watch` script
20
-
21
- 1. Run build in watch mode:
22
- `npm run build:watch`
23
- 2. Run `watch-and-copy.sh` in separate terminal:
24
- `bash ./scripts/watch-and-copy.sh ./lib/ ../<destination package/node_modules/@redocly/theme-experimental/`
25
-
26
- e.g. for reference docs:
27
- `bash ./scripts/watch-and-copy.sh ./lib/ ../reference-docs/node_modules/@redocly/theme-experimental/`
28
-
29
- **Important notes:**
30
-
31
- - build script will not remove files from target directory for safety reasons.
32
- - If you want to enable files removing - add `--delete` option to the `rsync` command in `scripts/watch-and-copy.sh`
33
- . **But please make sure you know what you're doing**, as it might wipe out destination directory content.
34
- - initial copy will be skipped
35
-
36
- ### 2. Use local registry (e.g. Verdaccio)
37
-
38
- 1. Build package:
39
- `npm run build`
40
- 1. Publish package to local registry:
41
- `cd lib`
42
- `npm publish --registry http://0.0.0.0:4873/`
43
- 1. Go to the depended package and Install package in the dependent repository:
44
- `npm i @redocly/theme-experimental --registry http://0.0.0.0:4873/`
45
- 1. Repeat above steps for every change in theme package.
46
-
47
- ### 3. Use `npm link`
48
-
49
- 1. Build package:
50
- `npm run build`
51
- 2. Link package:
52
- `cd lib` `npm link`
53
- 3. Go to the dependent package and Link package in the dependent repository:
54
- `npm link @redocly/theme-experimental`
55
- 4. Run `npm run build` after every change in the theme package
56
-
57
- **Notes:**
58
-
59
- - if you use nvm make sure you have same version of nodejs
60
- - Check if package is linked (note: link and run project should be in same terminal session):
61
- `ls -ald node_modules/@redocly/theme-experimental`
62
-
63
- **Unlink:**
64
-
65
- 1. Go to the dependent package and run unlink command
66
- `npm unlink --no-save @redocly/theme-experimental`
67
- 2. Remove the created link:
68
- `npm rm -g @redocly/theme-experimental`
69
-
70
- ## Merge PR to `main` branch
71
-
72
- Once you finished with changes in your PR, please, follow next flow:
73
-
74
- 1. Add `storybook-deploy` label to your PR
75
- 1. Wait until Storybook will be deployed to chromatic.com and check that `UI Tests` passed successfully
76
- 1. Go to chromatic [`UI Review`](https://www.chromatic.com/docs/review#review-changeset) page for your PR
77
- _(you can just click on `Details` button on `UI Review` commit check and you will be redirected to corresponding
78
- page)_
79
- 1. Ask you colleagues to review visual changes and approve them on chromatic.com
80
-
81
- > If you want to skip chromatic `UI Review` flow (e.g. for some chore PRs) you can add `storybook-skip` label to your
82
- > PR.
83
-
84
- > NOTE: Please, do not rename/regroup your stories (e.g. `'Components/Button'` -> `'Components/UI/MyButton'`) in the same PR with component refactoring/restyling. Chromatic will display your component as new component without ability to track visual changes.
85
-
86
- ## Useful scripts
87
-
88
- - `npm run lint` - check ESLint errors
89
- - `npm run lint:fix` - fix ESLint errors
90
- - `npm run ts:check` - static TS types check
91
- - `npm run oxfmt` - check formatter errors (not modify files)
92
- - `npm run oxfmt:fix` - fix formatter errors (modify files)
93
- - `npm test` - run unit tests
94
- - `npm run test:coverage` - run unit tests coverage
95
-
96
- # Publishing to npm
97
-
98
- To publish package to npm you should:
99
-
100
- 1. Bump up version in `package.json` based on [Semantic Versioning](https://semver.org/) rules
101
- 1. Create pull request with title like `chore: v1.2.3`
102
- 1. Merge PR to the `main` branch
103
- 1. Build and publish scripts/actions will be triggered automatically