Repository navigation
[component] feature: MaskedEdge - #488
consolecmnd wants to merge 4 commits into
Conversation
|
There was a problem hiding this comment.
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.
| mask-image: linear-gradient(#000, #000) !important; | ||
| mask-position: 0 0 !important; | ||
| mask-repeat: no-repeat !important; | ||
| mask-size: 100% 100% !important; |
There was a problem hiding this comment.
Why the need for all the !importants?
There was a problem hiding this comment.
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.
| /** | ||
| * 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 |
There was a problem hiding this comment.
combinations like
top bottom,left rightorall.
Could we figure out some fancy type gymnastics so that this statement is actually type-safe? Right now it'll technically accept any string.
There was a problem hiding this comment.
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>>
}
}|
|
||
| * The `bottom` and `right` mask images get flipped so the image points inwards | ||
| */ |
There was a problem hiding this comment.
This line seems oddly specific. Is this meant to be here, or is it maybe an example?
| /** | ||
| * Place the `image` over a predictable `frameAspect` container instead of one per edge | ||
| */ | ||
| fullFrame?: boolean |
There was a problem hiding this comment.
Just my opinion, but this feels out of the scope of this component. It is called Masked Edge after all. Thoughts?
| /** | ||
| * Aspect ratio of the container when `fullFrame` is set. | ||
| */ | ||
| frameAspect?: string | ||
| children?: ReactNode |
There was a problem hiding this comment.
Same. Just trying to assess whether this is necessary. I'm definitely open to it, but want to consider from all angles.
| 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}` | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| ) : null} | ||
|
|
There was a problem hiding this comment.
consider {masks.length > 0 && <AllYourMarkup>} rather than the ternary. Makes for better readability.
| {...rest} | ||
| className={classnames([ | ||
| styles.maskedEdge, | ||
| maskStyle ? styles.masked : null, |
There was a problem hiding this comment.
| maskStyle ? styles.masked : null, | |
| maskStyle && styles.masked, |
| <svg aria-hidden="true" className={styles.maskDefs} focusable="false"> | ||
| <defs> |
There was a problem hiding this comment.
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} />
}There was a problem hiding this comment.
Another approach could be to take the CSS mask-image route, completely removing the need for SVG.
marlonmarcello
left a comment
There was a problem hiding this comment.
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
| 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}` | ||
| } |
There was a problem hiding this comment.
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
| /** | ||
| * 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 |
There was a problem hiding this comment.
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>>
}
}| /** | ||
| * 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 |
There was a problem hiding this comment.
Let's remove string as option, enforce a number, easy to do calculations and removes ambiguity. You can then convert as you need.
| mask-image: linear-gradient(#000, #000) !important; | ||
| mask-position: 0 0 !important; | ||
| mask-repeat: no-repeat !important; | ||
| mask-size: 100% 100% !important; |
There was a problem hiding this comment.
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.
| <svg aria-hidden="true" className={styles.maskDefs} focusable="false"> | ||
| <defs> |
| @@ -0,0 +1,2 @@ | |||
| export { MaskedEdge } from "./masked-edge" | |||
There was a problem hiding this comment.
Should we drop the barrel file?
| function repeatLayerSize(side: MaskedEdgeSide, size: string): string { | ||
| return isVerticalSide(side) ? `${size} auto` : `auto ${size}` | ||
| } |
There was a problem hiding this comment.
I think we should pass tileSize to this function to better represent non-mirrored edges.
| 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.
Task
Contains
<MaskedEdge>Preview