Skip to content

Commit

Permalink
refactor: remove link box pattern (#2554)
Browse files Browse the repository at this point in the history
* refactor: link box

* chore: update
  • Loading branch information
segunadebayo authored May 1, 2024
1 parent 221c9a2 commit df2546a
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 150 deletions.
44 changes: 44 additions & 0 deletions .changeset/chilled-masks-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
'@pandacss/preset-base': minor
'@pandacss/generator': minor
'@pandacss/parser': minor
---

**BREAKING 💥**

Remove `linkBox` pattern in favor of using adding `position: relative` when using the `linkOverlay` pattern.

**Before**

```jsx
import { linkBox, linkOverlay } from 'styled-system/patterns'

const App = () => {
return (
<div className={linkBox()}>
<img src="https://via.placeholder.com/150" alt="placeholder" />
<a href="#" className={linkOverlay()}>
Link
</a>
</div>
)
}
```

**After**

```jsx
import { css } from 'styled-system/css'
import { linkOverlay } from 'styled-system/patterns'

const App = () => {
return (
<div className={css({ pos: 'relative' })}>
<img src="https://via.placeholder.com/150" alt="placeholder" />
<a href="#" className={linkOverlay()}>
Link
</a>
</div>
)
}
```
49 changes: 0 additions & 49 deletions packages/generator/__tests__/generate-pattern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,52 +450,6 @@ test('should generate pattern', () => {
import type { DistributiveOmit } from '../types/system-types';
import type { Tokens } from '../tokens/index';
export interface LinkBoxProperties {
}
interface LinkBoxStyles extends LinkBoxProperties, DistributiveOmit<SystemStyleObject, keyof LinkBoxProperties > {}
interface LinkBoxPatternFn {
(styles?: LinkBoxStyles): string
raw: (styles?: LinkBoxStyles) => SystemStyleObject
}
export declare const linkBox: LinkBoxPatternFn;
",
"js": "import { getPatternStyles, patternFns } from '../helpers.mjs';
import { css } from '../css/index.mjs';
const linkBoxConfig = {
transform(props) {
return {
position: "relative",
"& :where(a, abbr)": {
position: "relative",
zIndex: "1"
},
...props
};
}}
export const getLinkBoxStyle = (styles = {}) => {
const _styles = getPatternStyles(linkBoxConfig, styles)
return linkBoxConfig.transform(_styles, patternFns)
}
export const linkBox = (styles) => css(getLinkBoxStyle(styles))
linkBox.raw = getLinkBoxStyle",
"name": "link-box",
},
{
"dts": "import type { SystemStyleObject, ConditionalValue } from '../types/index';
import type { Properties } from '../types/csstype';
import type { SystemProperties } from '../types/style-props';
import type { DistributiveOmit } from '../types/system-types';
import type { Tokens } from '../tokens/index';
export interface LinkOverlayProperties {
}
Expand All @@ -517,12 +471,9 @@ test('should generate pattern', () => {
const linkOverlayConfig = {
transform(props) {
return {
position: "static",
_before: {
content: '""',
display: "block",
position: "absolute",
cursor: "inherit",
inset: "0",
zIndex: "0",
...props["_before"]
Expand Down
6 changes: 0 additions & 6 deletions packages/generator/__tests__/setup-artifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ describe('setup-artifacts', () => {
"patterns/circle.d.ts",
"patterns/center.mjs",
"patterns/center.d.ts",
"patterns/link-box.mjs",
"patterns/link-box.d.ts",
"patterns/link-overlay.mjs",
"patterns/link-overlay.d.ts",
"patterns/aspect-ratio.mjs",
Expand Down Expand Up @@ -227,8 +225,6 @@ describe('setup-artifacts', () => {
"patterns/circle.d.ts",
"patterns/center.mjs",
"patterns/center.d.ts",
"patterns/link-box.mjs",
"patterns/link-box.d.ts",
"patterns/link-overlay.mjs",
"patterns/link-overlay.d.ts",
"patterns/aspect-ratio.mjs",
Expand Down Expand Up @@ -282,8 +278,6 @@ describe('setup-artifacts', () => {
"jsx/circle.d.ts",
"jsx/center.mjs",
"jsx/center.d.ts",
"jsx/link-box.mjs",
"jsx/link-box.d.ts",
"jsx/link-overlay.mjs",
"jsx/link-overlay.d.ts",
"jsx/aspect-ratio.mjs",
Expand Down
69 changes: 17 additions & 52 deletions packages/parser/__tests__/preset-patterns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,14 @@ describe('preset patterns', () => {
`)
})

test('linkOverlay, linkBox', () => {
test('linkOverlay', () => {
const code = `
import { linkOverlay, linkBox } from "styled-system/patterns"
import { css } from "styled-system/css"
import { linkOverlay } from "styled-system/patterns"
function Button() {
return (
<div className={linkBox()}>
<div className={css({ pos: 'relative' })}>
<a className={linkOverlay()}>Click me</a>
</div>
)
Expand All @@ -494,10 +495,12 @@ describe('preset patterns', () => {
[
{
"data": [
{},
{
"pos": "relative",
},
],
"name": "linkBox",
"type": "pattern",
"name": "css",
"type": "css",
},
{
"data": [
Expand All @@ -515,30 +518,10 @@ describe('preset patterns', () => {
position: relative;
}
.pos_static {
position: static;
}
.\\[\\&_\\:where\\(a\\,_abbr\\)\\]\\:pos_relative :where(a, abbr) {
position: relative;
}
.\\[\\&_\\:where\\(a\\,_abbr\\)\\]\\:z_1 :where(a, abbr) {
z-index: 1;
}
.before\\:d_block::before {
display: block;
}
.before\\:pos_absolute::before {
position: absolute;
}
.before\\:cursor_inherit::before {
cursor: inherit;
}
.before\\:inset_0::before {
inset: var(--spacing-0);
}
Expand All @@ -554,15 +537,15 @@ describe('preset patterns', () => {
`)
})

test('jsx linkOverlay, linkBox', () => {
test('jsx linkOverlay', () => {
const code = `
import { LinkBox, LinkOverlay } from "styled-system/jsx"
import { Box, LinkOverlay } from "styled-system/jsx"
function Button() {
return (
<LinkBox>
<Box pos="relative">
<LinkOverlay>Click me</LinkOverlay>
</LinkBox>
</Box>
)
}
`
Expand All @@ -571,9 +554,11 @@ describe('preset patterns', () => {
[
{
"data": [
{},
{
"pos": "relative",
},
],
"name": "LinkBox",
"name": "Box",
"type": "jsx-pattern",
},
{
Expand All @@ -592,30 +577,10 @@ describe('preset patterns', () => {
position: relative;
}
.pos_static {
position: static;
}
.\\[\\&_\\:where\\(a\\,_abbr\\)\\]\\:pos_relative :where(a, abbr) {
position: relative;
}
.\\[\\&_\\:where\\(a\\,_abbr\\)\\]\\:z_1 :where(a, abbr) {
z-index: 1;
}
.before\\:d_block::before {
display: block;
}
.before\\:pos_absolute::before {
position: absolute;
}
.before\\:cursor_inherit::before {
cursor: inherit;
}
.before\\:inset_0::before {
inset: var(--spacing-0);
}
Expand Down
17 changes: 0 additions & 17 deletions packages/preset-base/src/patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,29 +317,13 @@ const divider = definePattern({
},
})

const linkBox = definePattern({
transform(props) {
return {
position: 'relative',
'& :where(a, abbr)': {
position: 'relative',
zIndex: '1',
},
...props,
}
},
})

const linkOverlay = definePattern({
jsxElement: 'a',
transform(props) {
return {
position: 'static',
_before: {
content: '""',
display: 'block',
position: 'absolute',
cursor: 'inherit',
inset: '0',
zIndex: '0',
...props['_before'],
Expand Down Expand Up @@ -472,7 +456,6 @@ export const patterns = {
square,
circle,
center,
linkBox,
linkOverlay,
aspectRatio,
grid,
Expand Down
1 change: 0 additions & 1 deletion packages/studio/styled-system/jsx/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export * from './spacer';
export * from './square';
export * from './circle';
export * from './center';
export * from './link-box';
export * from './link-overlay';
export * from './aspect-ratio';
export * from './grid';
Expand Down
1 change: 0 additions & 1 deletion packages/studio/styled-system/jsx/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export * from './spacer.mjs';
export * from './square.mjs';
export * from './circle.mjs';
export * from './center.mjs';
export * from './link-box.mjs';
export * from './link-overlay.mjs';
export * from './aspect-ratio.mjs';
export * from './grid.mjs';
Expand Down
1 change: 0 additions & 1 deletion packages/studio/styled-system/patterns/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from './spacer';
export * from './square';
export * from './circle';
export * from './center';
export * from './link-box';
export * from './link-overlay';
export * from './aspect-ratio';
export * from './grid';
Expand Down
1 change: 0 additions & 1 deletion packages/studio/styled-system/patterns/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export * from './spacer.mjs';
export * from './square.mjs';
export * from './circle.mjs';
export * from './center.mjs';
export * from './link-box.mjs';
export * from './link-overlay.mjs';
export * from './aspect-ratio.mjs';
export * from './grid.mjs';
Expand Down
3 changes: 0 additions & 3 deletions packages/studio/styled-system/patterns/link-overlay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import { css } from '../css/index.mjs';
const linkOverlayConfig = {
transform(props) {
return {
position: "static",
_before: {
content: '""',
display: "block",
position: "absolute",
cursor: "inherit",
inset: "0",
zIndex: "0",
...props["_before"]
Expand Down
Loading

0 comments on commit df2546a

Please sign in to comment.