forked from adobe/react-spectrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: codemods for Badge and Well (adobe#6941)
* add Well codemod * add migration docs for well * add codemod for badge * update well font * add story for testing style macro * add to migration docs
- Loading branch information
1 parent
95c8344
commit 32574f8
Showing
9 changed files
with
207 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/@react-spectrum/s2/stories/StyleMacro.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2024 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {Link} from '../src'; | ||
import React from 'react'; | ||
import {style} from '../style/spectrum-theme' with {type: 'macro'}; | ||
|
||
export default { | ||
title: 'S2 Style Macro', | ||
parameters: { | ||
docs: {disable: true} | ||
} | ||
}; | ||
|
||
export function Example() { | ||
return ( | ||
<div className={style({backgroundColor: 'orange-500', color: 'black', font: 'body', paddingX: 8, paddingY: 4, borderRadius: 'lg'})}> | ||
Test | ||
</div> | ||
); | ||
} | ||
|
||
export function Well() { | ||
return ( | ||
<div | ||
className={style({ | ||
display: 'block', | ||
textAlign: 'start', | ||
minWidth: 160, | ||
padding: 16, | ||
marginTop: 4, | ||
borderWidth: 1, | ||
borderRadius: 'sm', | ||
backgroundColor: 'layer-1', | ||
borderStyle: 'solid', | ||
borderColor: 'transparent-black-75', | ||
font: 'body-sm' | ||
})}> | ||
S2 style macro equivalent to v3 <Link href="https://react-spectrum.adobe.com/react-spectrum/Well.html" target="_blank">Well</Link>. | ||
</div> | ||
); | ||
} | ||
|
20 changes: 17 additions & 3 deletions
20
packages/dev/codemods/src/s1-to-s2/__tests__/__snapshots__/badge.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`No change 1`] = ` | ||
exports[`Change variant info to informative 1`] = ` | ||
"import { Badge } from "@react-spectrum/s2"; | ||
let variant = 'info'; | ||
let props = {variant: 'info'}; | ||
<div> | ||
<Badge variant="positive">Licensed</Badge> | ||
<Badge variant="informative"> | ||
Content Info | ||
</Badge> | ||
<Badge variant={"informative"}> | ||
Content Info | ||
</Badge> | ||
<Badge // TODO(S2-upgrade): Prop variant could not be automatically updated because variant could not be followed. | ||
variant={variant}> | ||
Content Info | ||
</Badge> | ||
<Badge // TODO(S2-upgrade): check this spread for style props | ||
{...props}> | ||
Content Info | ||
</Badge> | ||
</div>" | ||
`; |
44 changes: 44 additions & 0 deletions
44
packages/dev/codemods/src/s1-to-s2/__tests__/__snapshots__/well.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Updates Well to be div with style macro 1`] = ` | ||
"import { Well } from "@react-spectrum/s2"; | ||
import { style } from "@react-spectrum/s2/style" with { type: "macro" }; | ||
<div> | ||
<div | ||
className={style({ | ||
display: "block", | ||
textAlign: "start", | ||
minWidth: 160, | ||
padding: 16, | ||
marginTop: 4, | ||
borderWidth: 1, | ||
borderRadius: "sm", | ||
backgroundColor: "layer-1", | ||
borderStyle: "solid", | ||
borderColor: "transparent-black-75", | ||
font: "body-sm" | ||
})}> | ||
Well content | ||
</div> | ||
<div | ||
role="region" | ||
aria-labelledby="wellLabel" | ||
className={style({ | ||
display: "block", | ||
textAlign: "start", | ||
minWidth: 160, | ||
padding: 16, | ||
marginTop: 4, | ||
borderWidth: 1, | ||
borderRadius: "sm", | ||
backgroundColor: "layer-1", | ||
borderStyle: "solid", | ||
borderColor: "transparent-black-75", | ||
font: "body-sm" | ||
})}> | ||
<h3 id="wellLabel">Shipping Address</h3> | ||
<p>601 Townsend Street<br /> San Francisco, CA 94103</p> | ||
</div> | ||
</div>" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// @ts-ignore | ||
import {defineSnapshotTest} from 'jscodeshift/dist/testUtils'; | ||
import transform from '../src/codemods/codemod'; | ||
|
||
const test = (name: string, input: string) => { | ||
defineSnapshotTest(transform, {}, input, name); | ||
}; | ||
|
||
test('Updates Well to be div with style macro', ` | ||
import {Well} from '@adobe/react-spectrum'; | ||
<div> | ||
<Well> | ||
Well content | ||
</Well> | ||
<Well role="region" aria-labelledby="wellLabel"> | ||
<h3 id="wellLabel">Shipping Address</h3> | ||
<p>601 Townsend Street<br /> San Francisco, CA 94103</p> | ||
</Well> | ||
</div> | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters