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

OUTLINE-167: outline-core-heading: Heading Component #403

Draft
wants to merge 13 commits into
base: next
Choose a base branch
from

Conversation

shaal
Copy link
Contributor

@shaal shaal commented Jun 27, 2023

Description

<outline-core-heading>

Summary by CodeRabbit

  • New Features

    • Introduced outline-core-heading component with customizable classes, heading levels, sizes, and weights.
    • Added full card clickability with clickable-card class.
    • New test suite for outline-heading component to ensure proper functionality.
  • Enhancements

    • Updated outline-storybook with new CSS variables for improved design customization.
    • Modified outline-heading stories to reflect new component properties and import paths.
  • Documentation

    • Updated README for outline-core-heading with component summary and properties.
  • Style

    • Added CSS styling rules for text sizes and font weights in outline-core-heading.
    • Introduced new CSS rule for shiny class in outline-extended-button.
  • Refactor

    • Changed import paths and order for better organization and maintainability.
    • Extended OutlineCoreButton to create OutlineExtendedButton with additional variant shiny.

@changeset-bot
Copy link

changeset-bot bot commented Jun 27, 2023

⚠️ No Changeset found

Latest commit: 2f08402

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Jun 27, 2023

Deploy Preview for outlinejs failed.

Name Link
🔨 Latest commit 2f08402
🔍 Latest deploy log https://app.netlify.com/sites/outlinejs/deploys/65c24416d01d9600088b9283

@shaal shaal self-assigned this Jun 27, 2023
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this entire file. Generated via yarn turbo:version at release time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Try running yarn analyze to regenerate README files as needed. If others change, only include updates to this particular component.

@@ -0,0 +1,40 @@
{
"name": "@phase2/outline-core-heading",
"version": "0.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

0.0.1

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, last time with core link, it started at 0.0.1., and when the initial release was triggered, it created 0.0.2.

Let's try removing the version line entirely for a NEW package.

@himerus himerus changed the title feat: initial outline-core-heading outline-core-heading: Heading Component Aug 2, 2023
@himerus himerus added Why: Reduce adoption friction Severity: High Why: Increase standardization NEW PACKAGE A Pull Request that creates a new NPM package to be released. labels Aug 2, 2023
@socket-security
Copy link

socket-security bot commented Aug 8, 2023

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@phase2/[email protected] None +1 453 kB himerus

View full report↗︎

@shaal shaal requested a review from himerus August 8, 2023 13:25
@shaal shaal removed the Needs Work label Aug 8, 2023
@shaal shaal marked this pull request as ready for review August 10, 2023 13:54
@himerus himerus changed the title outline-core-heading: Heading Component OUTLINE-167: outline-core-heading: Heading Component Aug 10, 2023
}): TemplateResult {
return html`

<slot class=${classMap(classes)}></slot>
Copy link
Contributor

Choose a reason for hiding this comment

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

This will not work. Are there tests/samples in Storybook that show this usage with the classes applied properly?

You cannot directly attach classes to the element. The element is a placeholder inside a web component that users can fill with their own markup. The classes you apply to the element itself do not have any effect on the slotted content.

The classes applied to the element are considered part of the Shadow DOM, not the Light DOM. The Light DOM refers to the normal DOM tree, outside of the Shadow DOM, where the user's content lives. The Shadow DOM is a separate DOM tree attached to an element, providing encapsulation.

Copy link

coderabbitai bot commented Dec 5, 2023

Walkthrough

The overall change introduces a new outline-core-heading component with customizable properties for classes, heading levels, sizes, and weights. It includes updates to CSS for styling, tests for the new component, and storybook configurations. Additionally, there's an outline-extended-button that extends the core button functionality with a new variant. The changes are spread across component definitions, configurations, styles, and documentation updates.

Changes

File Path Change Summary
.../outline-core-heading/README.md Added documentation for outline-core-heading component.
.../outline-core-heading/index.ts Exported OutlineCoreHeading component and related types.
.../outline-core-heading/src/config.ts Updated HeadingSizes and HeadingWeights with specific values and types.
.../outline-core-heading/src/...core-heading.css Added CSS styling rules for text sizes and font weights.
.../outline-core-heading/src/...core-heading.lightdom.css Added CSS classes for text sizes, font weights, and clickable card.
.../outline-core-heading/src/outline-core-heading.ts Introduced OutlineCoreHeading component with properties and methods.
.../outline-core-heading/src/test/...core-heading.test.ts Added test suite for outline-core-heading component.
.../outline-storybook/config/storybook.main.css Reformatted and added new CSS variables.
.../outline-storybook/stories/...heading.stories.ts Updated imports and properties for outline-core-heading stories.
.../outline-templates/default/src/.../outline-extended-button/index.ts Exported OutlineExtendedButton.
.../outline-templates/default/src/.../outline-extended-button/outline-extended-button.css Added new CSS rule for class "shiny".
.../outline-templates/default/src/.../outline-extended-button/outline-extended-button.ts Modified imports, updated button variants, and declared OutlineExtendedButton class.

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 10

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1936c8b and 20efc04.
Files ignored due to filter (5)
  • packages/components/outline-core-heading/package.json
  • packages/components/outline-core-heading/tsconfig.build.json
  • packages/outline-templates/default/src/components/sample/outline-extended-button/package.json
  • packages/outline-templates/default/src/components/sample/outline-extended-button/tsconfig.build.json
  • yarn.lock
Files selected for processing (12)
  • packages/components/outline-core-heading/README.md (1 hunks)
  • packages/components/outline-core-heading/index.ts (1 hunks)
  • packages/components/outline-core-heading/src/config.ts (1 hunks)
  • packages/components/outline-core-heading/src/outline-core-heading.css (1 hunks)
  • packages/components/outline-core-heading/src/outline-core-heading.lightdom.css (1 hunks)
  • packages/components/outline-core-heading/src/outline-core-heading.ts (1 hunks)
  • packages/components/outline-core-heading/src/test/outline-core-heading.test.ts (1 hunks)
  • packages/documentation/outline-storybook/config/storybook.main.css (3 hunks)
  • packages/documentation/outline-storybook/stories/components/outline-heading.stories.ts (3 hunks)
  • packages/outline-templates/default/src/components/sample/outline-extended-button/index.ts (1 hunks)
  • packages/outline-templates/default/src/components/sample/outline-extended-button/outline-extended-button.css (1 hunks)
  • packages/outline-templates/default/src/components/sample/outline-extended-button/outline-extended-button.ts (1 hunks)
Files skipped from review due to trivial changes (6)
  • packages/components/outline-core-heading/index.ts
  • packages/components/outline-core-heading/src/outline-core-heading.css
  • packages/components/outline-core-heading/src/outline-core-heading.lightdom.css
  • packages/documentation/outline-storybook/config/storybook.main.css
  • packages/outline-templates/default/src/components/sample/outline-extended-button/index.ts
  • packages/outline-templates/default/src/components/sample/outline-extended-button/outline-extended-button.css
Additional comments: 16
packages/components/outline-core-heading/README.md (2)
  • 8-8: The level property type should be more specific to reflect the allowed heading levels as per the summary which mentions AllowedHeadingLevels. Please verify if the type should be AllowedHeadingLevels instead of string | undefined.

  • 16-17: The methods fullMarkupInSlot and generateHeading have a return type of TemplateResult<ResultType>. It would be helpful to specify what ResultType refers to, or if it is a placeholder, consider providing the actual return type for clarity.

packages/components/outline-core-heading/src/config.ts (2)
  • 1-1: Verify the intention behind including undefined in the HeadingLevels array to ensure it aligns with the component's design requirements.

  • 5-27: The configuration for HeadingSizes and HeadingWeights is well-defined, ensuring type safety and a clear set of options for these properties.

packages/components/outline-core-heading/src/outline-core-heading.ts (1)
  • 137-141: The conditional rendering logic in the render method is correct and follows best practices.
packages/components/outline-core-heading/src/test/outline-core-heading.test.ts (3)
  • 4-4: The test suite description uses outline-heading instead of outline-core-heading. Ensure that the test descriptions accurately reflect the component being tested.

  • 10-20: The test 'renders with default values' correctly checks the shadow DOM structure. Ensure that the default rendering of the component matches this structure.

  • 22-25: The test 'renders with slotted content' correctly checks the light DOM for the presence of the slotted text.

packages/documentation/outline-storybook/stories/components/outline-heading.stories.ts (6)
  • 6-14: The import statements and component usage have been correctly updated to reflect the new outline-core-heading component.

  • 15-15: The levelOptions array is correctly defined for use in the Storybook configuration.

  • 24-52: The Storybook configuration has been updated to reflect the new properties of the outline-core-heading component.

  • 62-67: The documentation provided in the Storybook parameters offers clear instructions on the usage of the outline-core-heading component.

  • 72-80: The template function and story examples have been updated to use the outline-core-heading component with the correct properties.

  • 93-154: The examples for slotted headings with and without attributes, as well as the Shadow DOM example, have been correctly updated to use the outline-core-heading component and its properties.

packages/outline-templates/default/src/components/sample/outline-extended-button/outline-extended-button.ts (2)
  • 4-5: The commented code and associated comment on lines 4-5 may indicate a version breaking change. It's important to document such changes clearly for future maintainability.

  • 13-14: The OutlineExtendedButton class extends OutlineCoreButton but does not add any new functionality or override any existing methods. If this is intentional and future extensions are planned, it's fine; otherwise, consider adding functionality or documenting the purpose of this extension.

Comment on lines +6 to +7
const el = document.createElement('outline-heading');
assert.instanceOf(el, OutlineCoreHeading);
Copy link

Choose a reason for hiding this comment

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

The element creation uses outline-heading instead of outline-core-heading. The test should create an instance of the component that matches the class being tested.

- const el = document.createElement('outline-heading');
+ const el = document.createElement('outline-core-heading');

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const el = document.createElement('outline-heading');
assert.instanceOf(el, OutlineCoreHeading);
const el = document.createElement('outline-core-heading');
assert.instanceOf(el, OutlineCoreHeading);

@@ -0,0 +1,14 @@
import { OutlineCoreButton } from '@phase2/outline-core-button';
import { customElement } from 'lit/decorators.js';
import '@phase2/outline-core-button';
Copy link

Choose a reason for hiding this comment

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

The import statement for @phase2/outline-core-button on line 3 is redundant since OutlineCoreButton is already imported on line 1 and should be removed to clean up the code.

- import '@phase2/outline-core-button';

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import '@phase2/outline-core-button';

// import { buttonVariantsTypes } from "@phase2/outline-core-button/src/outline-core-button";
import { buttonVariantsTypes } from '../outline-core-button/src/outline-core-button';

buttonVariantsTypes.push('shiny');
Copy link

Choose a reason for hiding this comment

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

Directly modifying an imported array like buttonVariantsTypes on line 8 can have unintended side effects if this array is shared across different modules. Consider using a more controlled approach to extend this array.

Comment on lines +10 to +11
// Rewriting does not work
// const buttonVariantsTypes = ['shiny', 'dull', 'matte'];
Copy link

Choose a reason for hiding this comment

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

The commented out code on lines 10-11 suggests an alternative approach that was not taken. If this code is not needed, it should be removed to avoid confusion.

- // Rewriting does not work
- // const buttonVariantsTypes = ['shiny', 'dull', 'matte'];

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// Rewriting does not work
// const buttonVariantsTypes = ['shiny', 'dull', 'matte'];

@customElement('outline-core-heading')
export class OutlineCoreHeading extends OutlineElement {
static styles = [componentStyles];
AdoptedStyleSheets: AdoptedStyleSheets;
Copy link

Choose a reason for hiding this comment

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

The AdoptedStyleSheets property should be private and follow camelCase naming conventions.

- AdoptedStyleSheets: AdoptedStyleSheets;
+ private adoptedStyleSheets: AdoptedStyleSheets;

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
AdoptedStyleSheets: AdoptedStyleSheets;
private adoptedStyleSheets: AdoptedStyleSheets;


connectedCallback() {
super.connectedCallback();
this.AdoptedStyleSheets = new AdoptedStyleSheets(globalStyles);
Copy link

Choose a reason for hiding this comment

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

After renaming AdoptedStyleSheets to adoptedStyleSheets, update the reference in connectedCallback.

- this.AdoptedStyleSheets = new AdoptedStyleSheets(globalStyles);
+ this.adoptedStyleSheets = new AdoptedStyleSheets(globalStyles);

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
this.AdoptedStyleSheets = new AdoptedStyleSheets(globalStyles);
this.adoptedStyleSheets = new AdoptedStyleSheets(globalStyles);

Comment on lines +68 to +72
converter: size => {
if (size && !Object.values(allowedHeadingSizes).includes(size)) {
size = allowedHeadingSizes[0];
}
return size;
Copy link

Choose a reason for hiding this comment

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

The size converter uses Object.values which is not necessary since allowedHeadingSizes is an array.

- if (size && !Object.values(allowedHeadingSizes).includes(size)) {
+ if (size && !allowedHeadingSizes.includes(size)) {

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
converter: size => {
if (size && !Object.values(allowedHeadingSizes).includes(size)) {
size = allowedHeadingSizes[0];
}
return size;
converter: size => {
if (size && !allowedHeadingSizes.includes(size)) {
size = allowedHeadingSizes[0];
}
return size;

Comment on lines +85 to +89
converter: weight => {
if (weight && !Object.values(allowedHeadingWeights).includes(weight)) {
weight = allowedHeadingWeights[0];
}
return weight;
Copy link

Choose a reason for hiding this comment

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

The weight converter uses Object.values which is not necessary since allowedHeadingWeights is an array.

- if (weight && !Object.values(allowedHeadingWeights).includes(weight)) {
+ if (weight && !allowedHeadingWeights.includes(weight)) {

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
converter: weight => {
if (weight && !Object.values(allowedHeadingWeights).includes(weight)) {
weight = allowedHeadingWeights[0];
}
return weight;
converter: weight => {
if (weight && !allowedHeadingWeights.includes(weight)) {
weight = allowedHeadingWeights[0];
}
return weight;

Comment on lines +129 to +130
if (this.size) {
slottedHeading?.classList.add(this.size as string);
Copy link

Choose a reason for hiding this comment

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

Ensure that this.size is a valid key before adding it as a class.

- slottedHeading?.classList.add(this.size as string);
+ if (allowedHeadingSizes.includes(this.size)) {
+   slottedHeading?.classList.add(this.size);
+ }

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (this.size) {
slottedHeading?.classList.add(this.size as string);
if (this.size) {
if (allowedHeadingSizes.includes(this.size)) {
slottedHeading?.classList.add(this.size);
}

Comment on lines +132 to +133
if (this.weight) {
slottedHeading?.classList.add(this.weight as string);
Copy link

Choose a reason for hiding this comment

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

Ensure that this.weight is a valid key before adding it as a class.

- slottedHeading?.classList.add(this.weight as string);
+ if (allowedHeadingWeights.includes(this.weight)) {
+   slottedHeading?.classList.add(this.weight);
+ }

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (this.weight) {
slottedHeading?.classList.add(this.weight as string);
if (this.weight) {
if (allowedHeadingWeights.includes(this.weight)) {
slottedHeading?.classList.add(this.weight);
}

@glitchgirl glitchgirl marked this pull request as draft February 6, 2024 14:41
@glitchgirl
Copy link
Contributor

TODO:
@shaal -review and update CSS to be nicer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants