Skip to content

Commit f5b64b8

Browse files
author
Rúben Carvalho
authored
feat: Add code view component (#5)
* feat: Add Code View component
1 parent 9e033f6 commit f5b64b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+15800
-22
lines changed

.github/ISSUE_TEMPLATE/2_feature_request.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ body:
2222
- label: I agree to follow this project's [Code of
2323
Conduct](https://github.com/cloudscape-design/components/blob/main/CODE_OF_CONDUCT.md)
2424
required: true
25-
- label:
26-
I checked the current issues on [this](https://github.com/cloudscape-design/code-view/issues) and
25+
- label: I checked the current issues on [this](https://github.com/cloudscape-design/code-view/issues) and
2726
[main](https://github.com/cloudscape-design/components/issues) repositories for duplicate requests

.stylelintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": ["stylelint-config-recommended-scss"],
3+
"rules": {
4+
"property-disallowed-list": ["border", "border-radius", "border-style", "margin", "padding"],
5+
"scss/comment-no-empty": null,
6+
"selector-pseudo-class-no-unknown": [true, { "ignorePseudoClasses": ["global"] }],
7+
"selector-max-type": [0, { "ignore": ["compounded"] }],
8+
"selector-max-universal": [0],
9+
"order/order": ["rules"]
10+
},
11+
"plugins": ["stylelint-use-logical", "stylelint-order"]
12+
}

package-lock.json

Lines changed: 14440 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"name": "@cloudscape-design/code-view",
3+
"version": "3.0.0",
4+
"repository": {
5+
"type": "git",
6+
"url": "https://github.com/cloudscape-design/code-view.git"
7+
},
8+
"homepage": "https://cloudscape.design",
9+
"scripts": {
10+
"prebuild": "rm -rf lib dist .cache",
11+
"build": "npm-run-all build:pkg --parallel build:src:* --parallel build:pages:*",
12+
"lint": "eslint --ignore-path .gitignore --ext ts,tsx,js . && stylelint --ignore-path .gitignore '{src,pages}/**/*.{css,scss}'",
13+
"prepare": "husky install",
14+
"test:unit": "vitest run --config vite.unit.config.mjs",
15+
"test:visual": "run-p -r preview test:visual:vitest",
16+
"test:visual:vitest": "vitest run --config vite.e2e-visual.config.mjs",
17+
"test:visual:update": "UPDATE_SCREENSHOTS=true npm run test:visual",
18+
"pretest": "tsc -p tsconfig.unit.json && tsc -p tsconfig.e2e.json",
19+
"test": "run-s lint test:unit",
20+
"preview": "vite preview",
21+
"start": "run-p start:server start:watch:ts start:watch:css",
22+
"start:server": "vite",
23+
"start:watch:ts": "tsc --watch",
24+
"start:watch:css": "chokidar \"./src/**/*.scss\" -c \"npm run build:src:css\"",
25+
"build:pkg": "node scripts/package-json.js",
26+
"build:src:js": "tsc -p tsconfig.json",
27+
"build:src:css": "node scripts/compile-styles.js",
28+
"build:src:test-utils": "node scripts/test-utils.js",
29+
"build:src:copy": "cp README.md lib/components/",
30+
"build:src:docs": "node scripts/docs.js",
31+
"build:src:environment": "node scripts/environment",
32+
"build:pages:vite": "vite build",
33+
"build:pages:tsc": "tsc -p pages/tsconfig.json"
34+
},
35+
"exports": {
36+
".": "./index.js",
37+
"./code-view": "./code-view/index.js",
38+
"./highlight": "./code-view/highlight/index.js",
39+
"./highlight/cpp": "./code-view/highlight/cpp.js",
40+
"./highlight/csharp": "./code-view/highlight/csharp.js",
41+
"./highlight/css": "./code-view/highlight/css.js",
42+
"./highlight/go": "./code-view/highlight/go.js",
43+
"./highlight/html": "./code-view/highlight/html.js",
44+
"./highlight/java": "./code-view/highlight/java.js",
45+
"./highlight/javascript": "./code-view/highlight/javascript.js",
46+
"./highlight/json": "./code-view/highlight/json.js",
47+
"./highlight/jsx": "./code-view/highlight/jsx.js",
48+
"./highlight/kotlin": "./code-view/highlight/kotlin.js",
49+
"./highlight/markdown": "./code-view/highlight/markdown.js",
50+
"./highlight/php": "./code-view/highlight/php.js",
51+
"./highlight/python": "./code-view/highlight/python.js",
52+
"./highlight/ruby": "./code-view/highlight/ruby.js",
53+
"./highlight/rust": "./code-view/highlight/rust.js",
54+
"./highlight/sh": "./code-view/highlight/sh.js",
55+
"./highlight/swift": "./code-view/highlight/swift.js",
56+
"./highlight/typescript": "./code-view/highlight/typescript.js",
57+
"./highlight/xml": "./code-view/highlight/xml.js",
58+
"./highlight/yaml": "./code-view/highlight/yaml.js",
59+
"./internal/api-docs/*.js": "./internal/api-docs/*.js",
60+
"./test-utils/dom": "./test-utils/dom/index.js",
61+
"./test-utils/selectors": "./test-utils/selectors/index.js"
62+
},
63+
"dependencies": {
64+
"ace-code": "^1.32.3",
65+
"clsx": "^1.2.1"
66+
},
67+
"peerDependencies": {
68+
"@cloudscape-design/components": "^3",
69+
"react": "^18.2.0",
70+
"react-dom": "^18.2.0"
71+
},
72+
"devDependencies": {
73+
"@cloudscape-design/browser-test-tools": "^3.0.4",
74+
"@cloudscape-design/components": "^3",
75+
"@cloudscape-design/design-tokens": "^3",
76+
"@cloudscape-design/documenter": "^1.0.0",
77+
"@cloudscape-design/global-styles": "^1.0.1",
78+
"@cloudscape-design/test-utils-converter": "^1.0.0",
79+
"@cloudscape-design/theming-build": "^1",
80+
"@testing-library/jest-dom": "^5.16.5",
81+
"@testing-library/react": "^13.4.0",
82+
"@types/jest-image-snapshot": "^6.1.0",
83+
"@types/lodash": "^4.14.191",
84+
"@types/node": "^18.19.4",
85+
"@types/react": "^18.0.26",
86+
"@types/react-dom": "^18.0.10",
87+
"@typescript-eslint/eslint-plugin": "^5.48.0",
88+
"@typescript-eslint/parser": "^5.48.0",
89+
"@vitejs/plugin-react": "^4.2.1",
90+
"@vitest/coverage-istanbul": "^1.1.1",
91+
"chokidar-cli": "^3.0.0",
92+
"eslint": "^8.31.0",
93+
"eslint-config-prettier": "^8.6.0",
94+
"eslint-plugin-header": "^3.1.1",
95+
"eslint-plugin-import": "^2.26.0",
96+
"eslint-plugin-no-unsanitized": "^4.0.2",
97+
"eslint-plugin-prettier": "^4.2.1",
98+
"eslint-plugin-react": "^7.31.11",
99+
"eslint-plugin-react-hooks": "^4.6.0",
100+
"eslint-plugin-unicorn": "^45.0.2",
101+
"execa": "^6.1.0",
102+
"globby": "^13.1.3",
103+
"husky": "^8.0.3",
104+
"jest-image-snapshot": "^6.1.0",
105+
"jsdom": "^20.0.3",
106+
"lint-staged": "^13.1.0",
107+
"lodash": "^4.17.21",
108+
"lodash-es": "^4.17.21",
109+
"npm-run-all": "^4.1.5",
110+
"prettier": "^2.8.1",
111+
"react": "^18.2.0",
112+
"react-dom": "^18.2.0",
113+
"react-router-dom": "^6.6.1",
114+
"stylelint": "^15.11.0",
115+
"stylelint-config-recommended-scss": "^12.0.0",
116+
"stylelint-order": "^6.0.3",
117+
"stylelint-prettier": "^2.0.0",
118+
"stylelint-scss": "^5.0.1",
119+
"stylelint-use-logical": "^2.1.0",
120+
"typescript": "4.9.4",
121+
"vite": "^5.0.10",
122+
"vitest": "^1.1.1"
123+
},
124+
"//": "ensure that typedoc uses typescript 4.9.4. It prints a warning, but works",
125+
"overrides": {
126+
"typescript": "4.9.4"
127+
},
128+
"lint-staged": {
129+
"*.{js,jsx,ts,tsx}": [
130+
"eslint --fix"
131+
],
132+
"*.{scss,css}": [
133+
"stylelint --fix"
134+
],
135+
"package-lock.json": [
136+
"./scripts/prepare-package-lock.js"
137+
]
138+
}
139+
}

pages/app/index.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { HashRouter, Link, Route, Routes, useLocation } from "react-router-dom";
4+
import { pages } from "../pages";
5+
import Page from "./page";
6+
7+
export default function App() {
8+
return (
9+
<HashRouter>
10+
<Routes>
11+
<Route path="/" element={<Start />} />
12+
<Route path="/*" element={<PageWithFallback />} />
13+
</Routes>
14+
</HashRouter>
15+
);
16+
}
17+
18+
const Start = () => (
19+
<>
20+
<h1>Pages</h1>
21+
<main>
22+
<Index />
23+
</main>
24+
</>
25+
);
26+
27+
const Index = () => (
28+
<ul className="list">
29+
{pages.map((page) => (
30+
<li key={page}>
31+
<Link to={`${page}`}>{page}</Link>
32+
</li>
33+
))}
34+
</ul>
35+
);
36+
37+
const PageWithFallback = () => {
38+
const { pathname: page } = useLocation();
39+
40+
if (!page || !page.includes(page)) {
41+
return <span>Not Found</span>;
42+
}
43+
44+
return <Page pageId={page} />;
45+
};

pages/app/page-layout.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.content {
2+
padding-block: 20px;
3+
padding-inline: 20px;
4+
}

pages/app/page-layout.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { ReactNode } from "react";
4+
5+
import classnames from "./page-layout.module.css";
6+
7+
export interface PageLayoutProps {
8+
header?: ReactNode;
9+
children?: ReactNode;
10+
}
11+
12+
export default function PageLayout({ children, header }: PageLayoutProps) {
13+
return (
14+
<div className={classnames.content}>
15+
<header>{header}</header>
16+
<main>{children}</main>
17+
</div>
18+
);
19+
}

pages/app/page.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { SpaceBetween, Toggle } from "@cloudscape-design/components";
4+
import { Density, Mode, applyDensity, applyMode } from "@cloudscape-design/global-styles";
5+
import { Suspense } from "react";
6+
import { useEffect, useState } from "react";
7+
import { pagesMap } from "../pages";
8+
import PageLayout from "./page-layout";
9+
10+
export interface PageProps {
11+
pageId: string;
12+
}
13+
14+
export default function Page({ pageId }: PageProps) {
15+
const Component = pagesMap[pageId];
16+
const [dark, setDark] = useState(false);
17+
const [compact, setCompact] = useState(false);
18+
19+
useEffect(() => {
20+
applyMode(dark ? Mode.Dark : Mode.Light, document.documentElement);
21+
}, [dark]);
22+
23+
useEffect(() => {
24+
applyDensity(compact ? Density.Compact : Density.Comfortable, document.documentElement);
25+
}, [compact]);
26+
27+
return (
28+
<PageLayout>
29+
<Suspense fallback="Loading">
30+
<SpaceBetween direction="vertical" size="m">
31+
<a href="/index.html#">Back to all pages</a>
32+
<SpaceBetween direction="horizontal" size="m">
33+
<Toggle checked={dark} onChange={(event) => setDark(event.detail.checked)}>
34+
Dark mode
35+
</Toggle>
36+
<Toggle checked={compact} onChange={(event) => setCompact(event.detail.checked)}>
37+
Compact mode
38+
</Toggle>
39+
</SpaceBetween>
40+
</SpaceBetween>
41+
<Component />
42+
</Suspense>
43+
</PageLayout>
44+
);
45+
}

pages/code-view/simple.page.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { CodeView } from "../../lib/components";
5+
import { ScreenshotArea } from "../screenshot-area";
6+
export default function CodeViewPage() {
7+
return (
8+
<ScreenshotArea>
9+
<h1>Code View</h1>
10+
<CodeView content={"Hello World"} />
11+
</ScreenshotArea>
12+
);
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { Button, SpaceBetween } from "@cloudscape-design/components";
5+
import { CodeView } from "../../lib/components";
6+
import { ScreenshotArea } from "../screenshot-area";
7+
export default function CodeViewPage() {
8+
return (
9+
<ScreenshotArea>
10+
<h1>Code View</h1>
11+
<SpaceBetween direction="vertical" size="l">
12+
<CodeView actions={<Button ariaLabel="Copy code" iconName="copy"></Button>} content={`Lorem Ipsum `} />
13+
<CodeView
14+
actions={<Button ariaLabel="Copy code" iconName="copy"></Button>}
15+
content={`Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`}
16+
/>
17+
</SpaceBetween>
18+
</ScreenshotArea>
19+
);
20+
}

0 commit comments

Comments
 (0)