@redocly/theme 0.0.1 → 0.1.2

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.
Files changed (54) hide show
  1. package/{lib/src/index.ts → index.js} +0 -0
  2. package/package.json +1 -2
  3. package/LICENSE +0 -1
  4. package/lib/package.json +0 -91
  5. package/lib/src/Button/Button.tsx +0 -122
  6. package/lib/src/Button/index.ts +0 -1
  7. package/lib/src/CodeBlock/CodeBlock.ts +0 -125
  8. package/lib/src/CodeBlock/index.ts +0 -1
  9. package/lib/src/CopyButton/CopyButton.tsx +0 -26
  10. package/lib/src/CopyButton/CopyButtonWrapper.tsx +0 -52
  11. package/lib/src/CopyButton/index.ts +0 -2
  12. package/lib/src/Headings/Headings.ts +0 -23
  13. package/lib/src/Headings/index.ts +0 -1
  14. package/lib/src/JsonViewer/JsonViewer.tsx +0 -130
  15. package/lib/src/JsonViewer/index.ts +0 -1
  16. package/lib/src/JsonViewer/styled.ts +0 -103
  17. package/lib/src/Logo/Logo.tsx +0 -23
  18. package/lib/src/Navbar/Navbar.tsx +0 -60
  19. package/lib/src/Navbar/NavbarItem.tsx +0 -90
  20. package/lib/src/Navbar/NavbarMenu.tsx +0 -29
  21. package/lib/src/Panel/CodePanel.ts +0 -31
  22. package/lib/src/Panel/ContentPanel.ts +0 -43
  23. package/lib/src/Panel/DarkHeader.ts +0 -8
  24. package/lib/src/Panel/Panel.ts +0 -18
  25. package/lib/src/Panel/PanelBody.ts +0 -30
  26. package/lib/src/Panel/PanelComponent.tsx +0 -73
  27. package/lib/src/Panel/PanelHeader.ts +0 -25
  28. package/lib/src/Panel/PanelHeaderTitle.ts +0 -11
  29. package/lib/src/Panel/index.ts +0 -7
  30. package/lib/src/SamplesPanelControls/SamplesPanelControls.ts +0 -70
  31. package/lib/src/SamplesPanelControls/index.ts +0 -1
  32. package/lib/src/SidebarLogo/SidebarLogo.tsx +0 -47
  33. package/lib/src/SidebarLogo/index.ts +0 -1
  34. package/lib/src/SourceCode/SourceCode.tsx +0 -67
  35. package/lib/src/SourceCode/index.ts +0 -1
  36. package/lib/src/Tooltip/Tooltip.tsx +0 -171
  37. package/lib/src/Tooltip/index.ts +0 -1
  38. package/lib/src/globalStyle.ts +0 -512
  39. package/lib/src/hooks/index.ts +0 -3
  40. package/lib/src/hooks/useControl.ts +0 -20
  41. package/lib/src/hooks/useMount.ts +0 -8
  42. package/lib/src/hooks/useUnmount.ts +0 -10
  43. package/lib/src/icons/ShelfIcon/ShelfIcon.tsx +0 -45
  44. package/lib/src/icons/ShelfIcon/index.ts +0 -2
  45. package/lib/src/icons/index.ts +0 -1
  46. package/lib/src/mocks/Link.tsx +0 -7
  47. package/lib/src/mocks/utils.ts +0 -3
  48. package/lib/src/utils/ClipboardService.ts +0 -92
  49. package/lib/src/utils/css-variables.ts +0 -2
  50. package/lib/src/utils/highlight.ts +0 -81
  51. package/lib/src/utils/index.ts +0 -6
  52. package/lib/src/utils/jsonToHtml.ts +0 -122
  53. package/lib/src/utils/media-css.ts +0 -16
  54. package/lib/src/utils/theme-helpers.ts +0 -34
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.0.1",
3
+ "version": "0.1.2",
4
4
  "description": "Shared UI components",
5
5
  "author": "team@redocly.com",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -28,7 +28,6 @@
28
28
  "test": "jest",
29
29
  "test:watch": "jest --watch",
30
30
  "test:coverage": "jest --coverage",
31
- "prepare": "husky install",
32
31
  "chromatic": "chromatic --exit-zero-on-changes"
33
32
  },
34
33
  "peerDependencies": {
package/LICENSE DELETED
@@ -1 +0,0 @@
1
- (c) Copyright 2022 Redocly Inc, all rights reserved.
package/lib/package.json DELETED
@@ -1,91 +0,0 @@
1
- {
2
- "name": "@redocly/theme",
3
- "version": "0.0.1",
4
- "description": "Shared UI components",
5
- "author": "team@redocly.com",
6
- "license": "SEE LICENSE IN LICENSE",
7
- "main": "index.js",
8
- "typings": "index.d.ts",
9
- "files": [
10
- "lib"
11
- ],
12
- "scripts": {
13
- "start": "npm run storybook",
14
- "storybook": "start-storybook -p 6006",
15
- "build-storybook": "build-storybook",
16
- "clean": "rm -rf lib",
17
- "compile": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
18
- "build:copy": " cp -R src package.json .npmignore lib/",
19
- "build": "npm run clean && npm run compile && npm run build:copy",
20
- "build:watch": "npm run build && tsc --watch -p tsconfig.build.json & tsc-alias -w -p tsconfig.build.json",
21
- "deploy": "npm publish lib",
22
- "lint": "eslint . --ext .ts,.tsx --cache",
23
- "lint:fix": "eslint . --ext .ts,.tsx --fix",
24
- "prettier-base": "prettier \"**/*.{json,js,jsx,ts,tsx,yml,yaml,html,md}\"",
25
- "prettier": "npm run prettier-base -- --write",
26
- "prettier:check": "npm run prettier-base -- --check",
27
- "ts:check": "tsc --noEmit --skipLibCheck",
28
- "test": "jest",
29
- "test:watch": "jest --watch",
30
- "test:coverage": "jest --coverage",
31
- "prepare": "husky install",
32
- "chromatic": "chromatic --exit-zero-on-changes"
33
- },
34
- "peerDependencies": {
35
- "prismjs": "^1.28.0",
36
- "react": "^17.0.2",
37
- "react-dom": "^17.0.2",
38
- "styled-components": "^5.3.1"
39
- },
40
- "devDependencies": {
41
- "@storybook/addon-actions": "^6.4.22",
42
- "@storybook/addon-essentials": "^6.4.22",
43
- "@storybook/addon-interactions": "^6.4.22",
44
- "@storybook/addon-links": "^6.4.22",
45
- "@storybook/builder-webpack5": "^6.4.22",
46
- "@storybook/core-common": "^6.4.22",
47
- "@storybook/manager-webpack5": "^6.4.22",
48
- "@storybook/node-logger": "^6.4.22",
49
- "@storybook/preset-create-react-app": "^4.1.0",
50
- "@storybook/react": "^6.4.22",
51
- "@storybook/testing-library": "^0.0.11",
52
- "@testing-library/jest-dom": "^5.16.4",
53
- "@testing-library/react": "^12.1.4",
54
- "@testing-library/user-event": "^13.5.0",
55
- "@types/jest": "^27.4.1",
56
- "@types/node": "^16.11.26",
57
- "@types/prismjs": "^1.26.0",
58
- "@types/react": "^17.0.43",
59
- "@types/react-dom": "^17.0.14",
60
- "@types/styled-components": "^5.1.25",
61
- "@typescript-eslint/eslint-plugin": "^5.21.0",
62
- "@typescript-eslint/parser": "^5.22.0",
63
- "chromatic": "^6.5.4",
64
- "esbuild": "^0.14.38",
65
- "eslint": "^8.13.0",
66
- "eslint-config-prettier": "^8.5.0",
67
- "eslint-import-resolver-typescript": "^2.7.1",
68
- "eslint-plugin-import": "^2.26.0",
69
- "eslint-plugin-jest": "^26.1.4",
70
- "eslint-plugin-react": "^7.29.4",
71
- "eslint-plugin-react-hooks": "^4.5.0",
72
- "eslint-plugin-storybook": "^0.5.11",
73
- "husky": "^7.0.4",
74
- "jest": "^27.5.1",
75
- "jest-styled-components": "^7.0.8",
76
- "lint-staged": "^12.4.1",
77
- "prettier": "2.6.2",
78
- "react": "^17.0.2",
79
- "react-dom": "^17.0.2",
80
- "react-refresh": "^0.13.0",
81
- "react-scripts": "5.0.1",
82
- "styled-components": "^5.3.5",
83
- "ts-jest": "^27.1.4",
84
- "tsc-alias": "^1.6.7",
85
- "typescript": "^4.6.3",
86
- "webpack": "^5.72.0"
87
- },
88
- "lint-staged": {
89
- "**/*": "prettier --write --ignore-unknown"
90
- }
91
- }
@@ -1,122 +0,0 @@
1
- import styled, { css, FlattenSimpleInterpolation, keyframes, Keyframes } from 'styled-components';
2
-
3
- export type ButtonSize = 'small' | 'medium' | 'large' | 'xlarge' | string;
4
- export type ButtonColor = 'primary' | 'secondary' | 'default' | string;
5
- export type ButtonVariant = 'outlined' | 'contained';
6
-
7
- export interface ButtonProps {
8
- color?: ButtonColor;
9
- disabled?: boolean;
10
- blinking?: boolean;
11
- fullWidth?: boolean;
12
- variant?: ButtonVariant;
13
- size?: ButtonSize;
14
- extraClass?: string;
15
- }
16
-
17
- const getBlink = (): Keyframes => keyframes`
18
- 0% {
19
- color: var(--button-color);
20
- background-color: var(--button-active-background-color);
21
- }
22
-
23
- 50% {
24
- background-color: var(--button-background-color);
25
- }
26
-
27
- 100% {
28
- color: var(--button-color);
29
- background-color: var(--button-active-background-color);
30
- }
31
- `;
32
-
33
- const getSize = (size: ButtonSize = 'medium'): FlattenSimpleInterpolation => css`
34
- font-size: var(--button-${size}-font-size);
35
- padding: var(--button-${size}-padding);
36
- min-width: var(--button-${size}-min-width);
37
- `;
38
-
39
- export const baseButtonStyles = css`
40
- outline: none;
41
- border: none;
42
- border-radius: var(--button-border-radius);
43
- font-weight: var(--button-font-weight);
44
- font-size: 14px;
45
- padding: 2px 20px;
46
- cursor: pointer;
47
- transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
48
- line-height: 1;
49
-
50
- font-family: var(--button-font-family);
51
- box-shadow: var(--button-box-shadow);
52
-
53
- &:hover {
54
- box-shadow: var(--button-active-box-shadow);
55
- }
56
-
57
- &:active {
58
- box-shadow: var(--button-active-box-shadow);
59
- }
60
- `;
61
-
62
- export const Button = styled.button.attrs(({ color = 'default', extraClass }: ButtonProps) => ({
63
- className: `button-color-${color}${extraClass ? ` ${extraClass}` : ''}`,
64
- }))<ButtonProps>`
65
- text-decoration: none;
66
- text-align: center;
67
-
68
- width: ${({ fullWidth }) => (fullWidth ? '100%' : 'auto')};
69
-
70
- ${baseButtonStyles}
71
-
72
- ${({ variant }) =>
73
- variant === 'outlined'
74
- ? css`
75
- color: var(--button-background-color);
76
- border: 2px solid var(--button-background-color);
77
- background-color: transparent;
78
- &:hover {
79
- border: 2px solid var(--button-active-background-color);
80
- background-color: transparent;
81
- }
82
-
83
- &:active {
84
- border: 2px solid var(--button-outlined-active-border-color);
85
- }
86
- `
87
- : css`
88
- color: var(--button-color);
89
- background-color: var(--button-background-color);
90
- &:hover {
91
- background-color: var(--button-hover-background-color);
92
- }
93
-
94
- &:active {
95
- background-color: var(--button-active-background-color);
96
- }
97
- `};
98
-
99
- ${({ size }) => getSize(size)}
100
-
101
- & + & {
102
- margin-left: 0.85em;
103
- }
104
-
105
- ${({ blinking }) =>
106
- blinking &&
107
- css`
108
- pointer-events: none;
109
- animation: ${getBlink()} 1.2s infinite;
110
- `}
111
-
112
- ${({ disabled }) =>
113
- disabled &&
114
- css`
115
- &,
116
- &:hover {
117
- cursor: default;
118
- color: #999999;
119
- pointer-events: none;
120
- }
121
- `}
122
- `;
@@ -1 +0,0 @@
1
- export * from './Button';
@@ -1,125 +0,0 @@
1
- import styled from 'styled-components';
2
-
3
- export const CodeBlock = styled.div`
4
- max-height: var(--code-block-max-height, 600px);
5
- word-break: var(--code-block-word-break, initial);
6
- /**
7
- * Based on prism-dark.css
8
- */
9
- code[class*='language-'],
10
- pre[class*='language-'] {
11
- /* color: white;
12
- background: none; */
13
- text-shadow: 0 -0.1em 0.2em black;
14
- text-align: left;
15
- white-space: pre;
16
- word-spacing: normal;
17
- word-break: normal;
18
- word-wrap: normal;
19
- line-height: 1.5;
20
-
21
- -moz-tab-size: 4;
22
- -o-tab-size: 4;
23
- tab-size: 4;
24
-
25
- -webkit-hyphens: none;
26
- -moz-hyphens: none;
27
- -ms-hyphens: none;
28
- hyphens: none;
29
- }
30
-
31
- @media print {
32
- code[class*='language-'],
33
- pre[class*='language-'] {
34
- text-shadow: none;
35
- }
36
- }
37
-
38
- /* Code blocks */
39
- pre[class*='language-'] {
40
- padding: 1em;
41
- margin: 0.5em 0;
42
- overflow: auto;
43
- }
44
-
45
- .token.comment,
46
- .token.prolog,
47
- .token.doctype,
48
- .token.cdata {
49
- color: hsl(30, 20%, 50%);
50
- }
51
-
52
- .token.punctuation {
53
- opacity: 1;
54
- }
55
-
56
- .namespace {
57
- opacity: 0.7;
58
- }
59
-
60
- .token.property,
61
- .token.tag,
62
- .token.number,
63
- .token.constant,
64
- .token.symbol {
65
- color: var(--color-content-inverse);
66
- }
67
-
68
- .token.boolean {
69
- color: var(--color-error-500);
70
- }
71
-
72
- .token.selector,
73
- .token.attr-name,
74
- .token.string,
75
- .token.char,
76
- .token.builtin,
77
- .token.inserted {
78
- color: #fee39e;
79
-
80
- & + a,
81
- & + a:visited {
82
- color: #4ed2ba;
83
- text-decoration: underline;
84
- }
85
- }
86
-
87
- .token.property.string {
88
- color: #9efaa7;
89
- }
90
-
91
- .token.operator,
92
- .token.entity,
93
- .token.url,
94
- .token.variable {
95
- color: #f5b83d;
96
- }
97
-
98
- .token.atrule,
99
- .token.attr-value,
100
- .token.keyword {
101
- color: #ffdbf4;
102
- }
103
-
104
- .token.regex,
105
- .token.important {
106
- color: #e90;
107
- }
108
-
109
- .token.important,
110
- .token.bold {
111
- font-weight: bold;
112
- }
113
-
114
- .token.italic {
115
- font-style: italic;
116
- }
117
-
118
- .token.entity {
119
- cursor: help;
120
- }
121
-
122
- .token.deleted {
123
- color: red;
124
- }
125
- `;
@@ -1 +0,0 @@
1
- export * from './CodeBlock';
@@ -1,26 +0,0 @@
1
- import React, { useState } from 'react';
2
-
3
- import { Button } from '../Button';
4
-
5
- export interface CopyButtonProps {
6
- text: string;
7
- dataTestId?: string;
8
- }
9
-
10
- export const CopyButton = ({ text, dataTestId = 'copy-button' }: CopyButtonProps): JSX.Element => {
11
- const [title, setTitle] = useState('Copy');
12
-
13
- async function write() {
14
- await navigator.clipboard.writeText(text);
15
-
16
- setTitle('Copied!');
17
-
18
- setTimeout(() => setTitle('Copy'), 1500);
19
- }
20
-
21
- return (
22
- <Button color="secondary" onClick={write} data-cy={dataTestId}>
23
- {title}
24
- </Button>
25
- );
26
- };
@@ -1,52 +0,0 @@
1
- import React, { memo } from 'react';
2
-
3
- import { SamplesControlButton } from '../SamplesPanelControls';
4
- import { Tooltip } from '../Tooltip';
5
- import { useControl } from '../hooks';
6
- import { ClipboardService } from '../utils';
7
-
8
- export interface CopyButtonWrapperProps {
9
- data: unknown;
10
- children: (props: { renderCopyButton: () => JSX.Element }) => JSX.Element;
11
- dataTestId?: string;
12
- }
13
-
14
- function CopyButtonWrapperComponent({
15
- data,
16
- children,
17
- dataTestId = 'copy-button',
18
- }: CopyButtonWrapperProps): JSX.Element {
19
- const tooltip = useControl();
20
-
21
- const showTooltip = (): void => {
22
- tooltip.handleOpen();
23
-
24
- setTimeout(() => {
25
- tooltip.handleClose();
26
- }, 1500);
27
- };
28
-
29
- const copy = (): void => {
30
- const content = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
31
- ClipboardService.copyCustom(content);
32
- showTooltip();
33
- };
34
-
35
- const renderCopyButton = (): JSX.Element => {
36
- return (
37
- <Tooltip
38
- className="copy-button"
39
- tip={ClipboardService.isSupported() ? 'Copied' : 'Not supported in your browser'}
40
- open={tooltip.isOpened}
41
- >
42
- <SamplesControlButton onClick={copy} data-cy={dataTestId}>
43
- Copy
44
- </SamplesControlButton>
45
- </Tooltip>
46
- );
47
- };
48
-
49
- return children({ renderCopyButton });
50
- }
51
-
52
- export const CopyButtonWrapper = memo<CopyButtonWrapperProps>(CopyButtonWrapperComponent);
@@ -1,2 +0,0 @@
1
- export * from './CopyButtonWrapper';
2
- export * from './CopyButton';
@@ -1,23 +0,0 @@
1
- import styled from 'styled-components';
2
-
3
- import { typography } from '../utils';
4
-
5
- export const H1 = styled.h1`
6
- color: var(--color-content);
7
- margin: 0 0 25px;
8
-
9
- ${typography('h1', 'h')};
10
- `;
11
-
12
- export const H2 = styled.h2`
13
- color: var(--color-content);
14
- margin: 0 0 20px;
15
-
16
- ${typography('h2', 'h')};
17
- `;
18
-
19
- export const H3 = styled.h3`
20
- color: var(--color-content);
21
-
22
- ${typography('h3', 'h')};
23
- `;
@@ -1 +0,0 @@
1
- export * from './Headings';
@@ -1,130 +0,0 @@
1
- import React, { memo, useRef, ReactElement } from 'react';
2
- import styled from 'styled-components';
3
-
4
- import { CopyButtonWrapper } from '../CopyButton';
5
- import { SampleControls, SamplesControlButton } from '../SamplesPanelControls';
6
- import { jsonToHTML } from '../utils';
7
- import { useMount, useUnmount } from '../hooks';
8
- import { CodeBlock } from '../CodeBlock';
9
-
10
- import { jsonStyles } from './styled';
11
-
12
- export interface JsonProps {
13
- data: any;
14
- className?: string;
15
- jsonSampleExpandLevel: number;
16
- }
17
-
18
- function JsonComponent({ data, jsonSampleExpandLevel, className }: JsonProps): JSX.Element {
19
- const node = useRef<HTMLDivElement | null>(null);
20
-
21
- useMount(() => {
22
- node?.current?.addEventListener('click', clickListener);
23
- });
24
-
25
- useUnmount(() => {
26
- node?.current?.removeEventListener('click', clickListener);
27
- });
28
-
29
- const expandAll = () => {
30
- const elements = node?.current?.getElementsByClassName('collapsible');
31
- for (const collapsed of Array.prototype.slice.call(elements)) {
32
- const parentNode = collapsed.parentNode as Element;
33
- if (!parentNode) continue;
34
- parentNode.classList.remove('collapsed');
35
- parentNode.querySelector('.collapser')?.setAttribute('aria-label', 'collapse');
36
- }
37
- };
38
-
39
- const collapseAll = () => {
40
- const elements = node?.current?.getElementsByClassName('collapsible');
41
- // skip first item to avoid collapsing whole object/array
42
- const elementsArr = Array.prototype.slice.call(elements, 1);
43
-
44
- for (const expanded of elementsArr) {
45
- const parentNode = expanded.parentNode as Element;
46
- if (!parentNode) continue;
47
- parentNode.classList.add('collapsed');
48
- parentNode.querySelector('.collapser')?.setAttribute('aria-label', 'expand');
49
- }
50
- };
51
-
52
- const collapseElement = (target: HTMLElement) => {
53
- if (target.parentElement && target.className === 'collapser') {
54
- const collapsed = target.parentElement.getElementsByClassName('collapsible')[0];
55
- if (collapsed?.parentElement?.classList.contains('collapsed')) {
56
- collapsed.parentElement.classList.remove('collapsed');
57
- target.setAttribute('aria-label', 'collapse');
58
- } else {
59
- collapsed?.parentElement?.classList.add('collapsed');
60
- target.setAttribute('aria-label', 'expand');
61
- }
62
- }
63
- };
64
-
65
- const clickListener = (event: MouseEvent) => {
66
- collapseElement(event.target as HTMLElement);
67
- };
68
-
69
- const renderInner = ({ renderCopyButton }: { renderCopyButton: () => ReactElement }) => {
70
- const showFoldingButtons =
71
- data && Object.values(data).some((value) => typeof value === 'object' && value !== null);
72
-
73
- return (
74
- <JsonViewerWrap data-cy="json-viewer">
75
- <SampleControls data-cy="buttons">
76
- {renderCopyButton()}
77
- {showFoldingButtons && (
78
- <>
79
- <SamplesControlButton onClick={expandAll} data-cy="expand-all">
80
- Expand all
81
- </SamplesControlButton>
82
- <SamplesControlButton onClick={collapseAll} data-cy="collapse-all">
83
- Collapse all
84
- </SamplesControlButton>
85
- </>
86
- )}
87
- </SampleControls>
88
- <StyledCodeBlock
89
- className={className}
90
- ref={node}
91
- dangerouslySetInnerHTML={{
92
- __html: jsonToHTML(data, jsonSampleExpandLevel),
93
- }}
94
- />
95
- </JsonViewerWrap>
96
- );
97
- };
98
-
99
- return (
100
- <CopyButtonWrapper data-cy="copy-button" data={data}>
101
- {renderInner}
102
- </CopyButtonWrapper>
103
- );
104
- }
105
-
106
- export const Json = memo<JsonProps>(JsonComponent);
107
-
108
- export const JsonViewer = styled(Json)<JsonProps>`
109
- ${jsonStyles};
110
- `;
111
-
112
- export const JsonViewerWrap = styled.div`
113
- display: flex;
114
- flex-direction: column;
115
- flex: 1;
116
-
117
- &:hover > ${SampleControls} {
118
- opacity: 1;
119
- }
120
- `;
121
-
122
- export const StyledCodeBlock = styled(CodeBlock)`
123
- flex: 1;
124
-
125
- code {
126
- font-family: var(--code-font-family);
127
- font-size: 14px;
128
- line-height: 18px;
129
- }
130
- `;
@@ -1 +0,0 @@
1
- export * from './JsonViewer';