Skip to content

[component] feature: MaskedEdge - #488

Open
consolecmnd wants to merge 4 commits into
mainfrom
feature/maskedEdge
Open

consolecmnd wants to merge 4 commits into
mainfrom
feature/maskedEdge

Conversation

@consolecmnd

Copy link
Copy Markdown

Task

Contains

  • Add a new component called <MaskedEdge>
  • Uses an alpha mask to create unique contoured edges on a container

Preview

Screenshot 2026-11-13 at 11 52 56 am Screenshot 2026-11-13 at 11 53 20 am Screenshot 2026-11-13 at 11 53 27 am Screenshot 2026-11-13 at 11 53 34 am Screenshot 2026-11-13 at 11 53 42 am Screenshot 2026-11-13 at 11 53 49 am Screenshot 2026-11-13 at 11 53 56 am Screenshot 2026-11-13 at 11 54 02 am Screenshot 2026-11-13 at 11 54 10 am

@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 133505a

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like a few linting issues due to the name property being used on some of these stories. Let's clean those up and see if we can get CI to pass.

Comment on lines +61 to +64
mask-image: linear-gradient(#000, #000) !important;
mask-position: 0 0 !important;
mask-repeat: no-repeat !important;
mask-size: 100% 100% !important;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why the need for all the !importants?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's because the styles are added inline @andrewrubin . That said, maybe CSS custom properties and/or layer could solve the need for them.

Comment on lines +28 to +34
/**
* Sides that receive `image`.
* Accepts `top`, `bottom`, `left`, `right`, combinations like `top bottom`, `left right` or `all`.

* Defaults to all four sides when only `image` is provided
*/
sides?: string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

combinations like top bottom, left right or all.

Could we figure out some fancy type gymnastics so that this statement is actually type-safe? Right now it'll technically accept any string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with @andrewrubin here. I think both this and the top?: string, bottom?: string, left?: string, right?: string props could do with rework. A suggestion is to use an object, it will help compress the number of props and will allow for combining things into logic groups, and comes with the benefit that you enforce at least the props to be declared and have a value since you need at least one of the sides to be true.

This is just a suggestion:

type Sides = 'left' | 'right' | 'top' | 'bottom'

type MyType = {
  artwork?: Parial<Record<Sides, string>>
  sides: Partial<Record<Sides, boolean>>
 }
}

Comment on lines +54 to +56

* The `bottom` and `right` mask images get flipped so the image points inwards
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line seems oddly specific. Is this meant to be here, or is it maybe an example?

Comment on lines +59 to +62
/**
* Place the `image` over a predictable `frameAspect` container instead of one per edge
*/
fullFrame?: boolean

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just my opinion, but this feels out of the scope of this component. It is called Masked Edge after all. Thoughts?

Comment on lines +64 to +68
/**
* Aspect ratio of the container when `fullFrame` is set.
*/
frameAspect?: string
children?: ReactNode

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same. Just trying to assess whether this is necessary. I'm definitely open to it, but want to consider from all angles.

Comment on lines +108 to +119
function toLength(value: number | string | undefined, fallback: string): string {
if (value === undefined || value === "") return fallback
return typeof value === "number" ? `${value}px` : value
}

function isVerticalSide(side: MaskedEdgeSide): boolean {
return side === "left" || side === "right"
}

function edgeContainerSize(side: MaskedEdgeSide, size: string): string {
return isVerticalSide(side) ? `${size} 100%` : `100% ${size}`
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A lot of this file is utility functions! Consider putting these (and the rest) into a utilities or a lib folder within the masked-edge component folder.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To complement @andrewrubin's note, some of these are used only once, might as well just do it inline. Personally I also think that having a bunch of utility files adds unnecessary separation, just move these functions to the bottom of the file, always have types and the main export up first. Just doing that will clean up things considerably

Comment on lines +414 to +415
) : null}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

consider {masks.length > 0 && <AllYourMarkup>} rather than the ternary. Makes for better readability.

{...rest}
className={classnames([
styles.maskedEdge,
maskStyle ? styles.masked : null,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
maskStyle ? styles.masked : null,
maskStyle && styles.masked,

Comment on lines +340 to +341
<svg aria-hidden="true" className={styles.maskDefs} focusable="false">
<defs>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have some concerns around whether this approach is scalable. For example, if we need the same mask ten times on a page, this same <defs> tag will be repeated ten times on the page (which defeats the purpose of a <defs> tag).

Is there an alternative where we explore separating the defs tag, and allowing developers to import that on its own, at the top of their document for example? So the usage would be:

import { CoolMaskDefs } from "@components/whatever"

<MyPage>
  <CoolMaskDefs />
  <MySection />
</MyPage>
function MySection() {
  <MaskedEdge {stuff} />
  <MaskedEdge {stuff} />
  <MaskedEdge {stuff} />
  <MaskedEdge {stuff} />
  <MaskedEdge {stuff} />
  <MaskedEdge {stuff} />
  <MaskedEdge {stuff} />
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another approach could be to take the CSS mask-image route, completely removing the need for SVG.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with both here. And just a note, but solution #1 is inline with how we do icons, so it's a known pattern as well and solution #2 is cleaner. Both are good.

@marlonmarcello marlonmarcello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Couple linting issues comes from the storybook/no-redundant-story-name ESLint rule. It triggers when you explicitly define a name property on a Storybook story that matches the title Storybook already generates automatically

Comment on lines +108 to +119
function toLength(value: number | string | undefined, fallback: string): string {
if (value === undefined || value === "") return fallback
return typeof value === "number" ? `${value}px` : value
}

function isVerticalSide(side: MaskedEdgeSide): boolean {
return side === "left" || side === "right"
}

function edgeContainerSize(side: MaskedEdgeSide, size: string): string {
return isVerticalSide(side) ? `${size} 100%` : `100% ${size}`
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To complement @andrewrubin's note, some of these are used only once, might as well just do it inline. Personally I also think that having a bunch of utility files adds unnecessary separation, just move these functions to the bottom of the file, always have types and the main export up first. Just doing that will clean up things considerably

Comment on lines +28 to +34
/**
* Sides that receive `image`.
* Accepts `top`, `bottom`, `left`, `right`, combinations like `top bottom`, `left right` or `all`.

* Defaults to all four sides when only `image` is provided
*/
sides?: string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with @andrewrubin here. I think both this and the top?: string, bottom?: string, left?: string, right?: string props could do with rework. A suggestion is to use an object, it will help compress the number of props and will allow for combining things into logic groups, and comes with the benefit that you enforce at least the props to be declared and have a value since you need at least one of the sides to be true.

This is just a suggestion:

type Sides = 'left' | 'right' | 'top' | 'bottom'

type MyType = {
  artwork?: Parial<Record<Sides, string>>
  sides: Partial<Record<Sides, boolean>>
 }
}

Comment on lines +41 to +50
/**
* Size of one tile along the edge when `repeat` is used with `mirror`.
* Defaults to `size`. Numbers = pixels
*/
tileSize?: number | string

/**
* Thickness of the edge container. Numbers = pixels
*/
size?: number | string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's remove string as option, enforce a number, easy to do calculations and removes ambiguity. You can then convert as you need.

Comment on lines +61 to +64
mask-image: linear-gradient(#000, #000) !important;
mask-position: 0 0 !important;
mask-repeat: no-repeat !important;
mask-size: 100% 100% !important;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's because the styles are added inline @andrewrubin . That said, maybe CSS custom properties and/or layer could solve the need for them.

Comment on lines +340 to +341
<svg aria-hidden="true" className={styles.maskDefs} focusable="false">
<defs>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with both here. And just a note, but solution #1 is inline with how we do icons, so it's a known pattern as well and solution #2 is cleaner. Both are good.

@@ -0,0 +1,2 @@
export { MaskedEdge } from "./masked-edge"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we drop the barrel file?

Comment on lines +121 to +123
function repeatLayerSize(side: MaskedEdgeSide, size: string): string {
return isVerticalSide(side) ? `${size} auto` : `auto ${size}`
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should pass tileSize to this function to better represent non-mirrored edges.

Suggested change
function repeatLayerSize(side: MaskedEdgeSide, size: string): string {
return isVerticalSide(side) ? `${size} auto` : `auto ${size}`
}
function repeatLayerSize(side: MaskedEdgeSide, size: string, tileSize: string): string {
return isVerticalSide(side) ? `${size} ${tileSize}` : `${tileSize} ${size}`
}

Otherwise you get stretching in instances where the CSS is used.

This branch has not been deployed

No deployments
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.

4 participants