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

feat: Add code-view source code #3

Closed
wants to merge 7 commits into from
Closed

Conversation

rubencarvalho
Copy link
Contributor

@rubencarvalho rubencarvalho commented Dec 13, 2023

Added the initial source the code-view.

@rubencarvalho rubencarvalho changed the title feat: Add code-view source code and demos feat: Add code-view source code Dec 13, 2023
import Popover from "@cloudscape-design/components/popover";
import StatusIndicator from "@cloudscape-design/components/status-indicator";
import { useState } from "react";

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 can be deleted when an official component exists.

Copy link
Member

Choose a reason for hiding this comment

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

We cannot un-publish public APIs! Let's talk about this.

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 an internal, unofficial API but I think it's best if we just get rid of this entirely.

package.json Outdated
@@ -0,0 +1,108 @@
{
"name": "@cloudscape-design/code-view",
"type": "module",
Copy link
Member

Choose a reason for hiding this comment

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

Is this safe? I don't think we've done this for any other public NPM package so far.

"./highlight/xml": "./dist/highlight/xml.js",
"./highlight/yaml": "./dist/highlight/yaml.js"
},
"imports": {},
Copy link
Member

Choose a reason for hiding this comment

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

Not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed on new PR

"dependencies": {
"ace-code": "^1.32.0",
"clsx": "^1.2.1",
"rollup-plugin-ignore": "^1.0.10",
Copy link
Member

Choose a reason for hiding this comment

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

This is probably a dev dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed on new PR

import Box from "@cloudscape-design/components/box";
import clsx from "clsx";
import { CodeViewProps } from "./interfaces";
import * as classes from "./styles.css";
Copy link
Member

Choose a reason for hiding this comment

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

We usually call this styles in our main repository. Would be nice to be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated on new PR


return (
<div
className={clsx(
Copy link
Member

Choose a reason for hiding this comment

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

I think you also need to call getBaseProps here to pull in the className and id attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done on new PR

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import * as tokens from "@cloudscape-design/design-tokens";
import { createGlobalTheme, createThemeContract, style } from "@vanilla-extract/css";
Copy link
Member

Choose a reason for hiding this comment

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

Can't we just use sass? I would rather keep the frameworks consistent across our repositories.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated on new PR to align with the other components

import Popover from "@cloudscape-design/components/popover";
import StatusIndicator from "@cloudscape-design/components/status-indicator";
import { useState } from "react";

Copy link
Member

Choose a reason for hiding this comment

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

We cannot un-publish public APIs! Let's talk about this.

"build:environment": "node scripts/environment",
"build:copy": "cp README.md dist/",
"build:index": "cp src/index.* dist",
"build:highlight": "sass src/highlight/theme.scss dist/highlight/theme.css && tsc -p src/highlight/tsconfig.json",
Copy link
Member

Choose a reason for hiding this comment

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

I think we're using the ace theme now, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified this.

"build:highlight": "sass src/highlight/theme.scss dist/highlight/theme.css && tsc -p src/highlight/tsconfig.json",
"build:test": "node scripts/test-utils",
"build:rollup": "rollup --config rollup.config.js --bundleConfigAsCjs",
"build:tsc": "tsc --project ./demo/tsconfig.json",
Copy link
Member

Choose a reason for hiding this comment

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

Let's maybe call this build:demo? Otherwise it sounds like it would build the main bundle ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aligned it with board-components.

"prebuild": "rm -rf dist && mkdir dist",
"prepublishOnly": "npm run build",
"lint": "eslint --ignore-path .gitignore --ext ts,tsx,js --fix .",
"build": "npm-run-all build:*",
Copy link
Member

Choose a reason for hiding this comment

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

Can all these build steps be executed in a random order?

test("correctly renders component content", () => {
render(<CodeView content={"Hello World"}></CodeView>);
const wrapper = createWrapper().findCodeView()!;
expect(wrapper!.findContent().getElement().textContent).toBe("Hello World");
Copy link
Member

Choose a reason for hiding this comment

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

minor: I prefer .toHaveTextContent over .textContent).toBe because it feels like the better abstraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in new PR

expect(wrapper!.findLineNumbers()!.getElement().textContent).toBe("123");
});

test("correctly tokenizes content if highlight is set", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Should this also test that it doesnt apply the default highlighting from ace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will extend these tests on new PR

colorBackgroundCode: null,
});
createGlobalTheme(":root", vars, {
colorBackgroundCode: "#f4f4f4",
Copy link
Member

Choose a reason for hiding this comment

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

Can we use design tokens please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add this design token


export const code = style({
backgroundColor: vars.colorBackgroundCode,
padding: "8px",
Copy link
Member

Choose a reason for hiding this comment

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

Can we use design tokens please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used on new PR

html:not(.awsui-dark-mode) body:not(.awsui-dark-mode) {
@import "../../node_modules/ace-code/styles/theme/cloud_editor";
.ace-cloud_editor {
background: none;
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if there's any way to use the theme as-is, without this overwrite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our background color is very slightly different from the included one, so we need this.

@rubencarvalho
Copy link
Contributor Author

Adressed most (if not all of the comments here). Opened a new PR: #5

@michaeldowseza michaeldowseza deleted the code-view-only branch November 22, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants