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

feat: migration examples prefix selectors #13264

Merged
merged 25 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e5674f4
feat(ContentSwitcher): preliminary unstable refactor
andreancardona Aug 26, 2021
7071564
Merge branch 'main' of github.com:carbon-design-system/carbon
andreancardona Sep 3, 2021
0d12bdb
Merge branch 'main' of github.com:carbon-design-system/carbon
andreancardona Sep 20, 2021
bc65356
Merge branch 'main' of github.com:carbon-design-system/carbon
andreancardona Sep 20, 2021
87c325d
Merge branch 'main' of github.com:carbon-design-system/carbon
andreancardona Sep 24, 2021
98bc81a
Merge branch 'main' of github.com:carbon-design-system/carbon
andreancardona Oct 8, 2021
2e02582
Merge branch 'main' of github.com:carbon-design-system/carbon
andreancardona Feb 20, 2023
d875f9c
feat: added prefix and id prefix examples
andreancardona Mar 1, 2023
9e71a5c
fix: delete content switcher directory
andreancardona Mar 1, 2023
1e202ac
feat: update demos
andreancardona Mar 1, 2023
5bf7f3d
Merge branch 'main' into 12342-migration-examples-prefix-selectors
andreancardona Mar 1, 2023
c45bd9f
Update examples/id-prefix/src/App.jsx
andreancardona Mar 1, 2023
36adcf6
Update packages/react/src/components/IdPrefix/index.js
andreancardona Mar 1, 2023
fe7c047
feat: added docs
andreancardona Mar 2, 2023
7f8dbde
Merge branch '12342-migration-examples-prefix-selectors' of github.co…
andreancardona Mar 2, 2023
29afca0
fix: update context
andreancardona Mar 3, 2023
2e1b93c
fix: yarn install
andreancardona Mar 3, 2023
ea4b06f
fix: update context 2
andreancardona Mar 3, 2023
16cde8e
Merge branch 'andreancardona-12342-migration-examples-prefix-selectors'
andreancardona Mar 3, 2023
722ce0c
Merge branch '12342-migration-examples-prefix-selectors' of github.co…
andreancardona Mar 7, 2023
055fce5
Merge branch 'andreancardona-12342-migration-examples-prefix-selector…
andreancardona Mar 7, 2023
c7b7b6d
Merge branch 'main' of github.com:carbon-design-system/carbon into 12…
andreancardona Mar 7, 2023
c3c7df5
chore: update yarn packages
andreancardona Mar 7, 2023
06edde4
chore: udpate yarn carbon/react
andreancardona Mar 7, 2023
c6f0a30
Merge branch 'main' into 12342-migration-examples-prefix-selectors
kodiakhq[bot] Mar 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/class-prefix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
52 changes: 52 additions & 0 deletions examples/class-prefix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with
[`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Class Prefix

By default, the prefix used by components is cds. However, you can change this
prefix in Sass and coordinate that change to React using the ClassPrefix
component.

## Getting Started

First, run `yarn` or `npm install` and then run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the
result.

## Sass

First and foremost, if you want to use v11 styles in any capacity, you'll have
to migrate to use `dart-sass`. `node-sass` has been deprecated and we migrated
to `dart-sass` in v11. For more information about migrating, visit our docs
[here](https://github.com/carbon-design-system/carbon/blob/main/docs/migration/v11.md#changing-from-node-sass-to-sass).

In Sass, you can customize this prefix by writing the following:

`@use '@carbon/react' with ( $prefix: 'custom' );`

Similarly, you can configure scss/config directly:

`@use '@carbon/react/scss/config' with ( $prefix: 'custom' );`

## V11

This example is of how to use ClassPrefix from v11 🎉.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js
features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out
[the Next.js GitHub repository](https://github.com/vercel/next.js/) - your
feedback and contributions are welcome!
13 changes: 13 additions & 0 deletions examples/class-prefix/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions examples/class-prefix/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "class-prefix",
"private": true,
"version": "0.21.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@carbon/react": "^1.24.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "1.1.3",
"sass": "^1.51.0",
"vite": "^2.9.5"
}
}
24 changes: 24 additions & 0 deletions examples/class-prefix/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { usePrefix } from '@carbon/react';
import { ClassPrefix } from '@carbon/react';

function ExampleComponent() {
const prefix = usePrefix();

return (
<p>The current prefix is: {prefix}</p>
)
}

function App() {
return (
<>
<ExampleComponent />
<ClassPrefix prefix="custom">
<ExampleComponent />
</ClassPrefix>
</>
);
}

export default App
3 changes: 3 additions & 0 deletions examples/class-prefix/src/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use '@carbon/react' with (
$prefix: 'custom'
);
12 changes: 12 additions & 0 deletions examples/class-prefix/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './index.scss'

import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
11 changes: 11 additions & 0 deletions examples/class-prefix/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react({
jsxRuntime: 'classic',
}),
],
});
24 changes: 24 additions & 0 deletions examples/id-prefix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
49 changes: 49 additions & 0 deletions examples/id-prefix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with
[`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Id Prefix

This component is intended to be used in limited cases, primarily only if you
have id conflicts when using v10 and v11 packages at the same time during
migration.

In React, you can use IdPrefix anywhere in your component tree and specify the
prefix with the prefix prop. Most often it's used in the project root wrapping
the entire project

## Getting Started

First, run `yarn` or `npm install` and then run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the
result.

## Sass

First and foremost, if you want to use v11 styles in any capacity, you'll have
to migrate to use `dart-sass`. `node-sass` has been deprecated and we migrated
to `dart-sass` in v11. For more information about migrating, visit our docs
[here](https://github.com/carbon-design-system/carbon/blob/main/docs/migration/v11.md#changing-from-node-sass-to-sass).

## V10 and V11

This example is a v11 feature using the IdPrefix 🎉. As mentioned above, it will
help with any id conflicts as you migrate over to v11.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js
features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out
[the Next.js GitHub repository](https://github.com/vercel/next.js/) - your
feedback and contributions are welcome!
13 changes: 13 additions & 0 deletions examples/id-prefix/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions examples/id-prefix/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "id-prefix",
"private": true,
"version": "0.21.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@carbon/react": "^1.24.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "1.1.3",
"sass": "^1.51.0",
"vite": "^2.9.5"
}
}
24 changes: 24 additions & 0 deletions examples/id-prefix/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { useIdPrefix } from '@carbon/react';
import { IdPrefix } from '@carbon/react';

function ExampleComponent() {
const idPrefix = useIdPrefix();

return (
<p>The current id prefix is: {idPrefix}</p>
)
}

function App() {
return (
<>
<ExampleComponent />
<IdPrefix prefix="custom">
<ExampleComponent />
</IdPrefix>
</>
);
}

export default App
3 changes: 3 additions & 0 deletions examples/id-prefix/src/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use '@carbon/react' with (
$prefix: 'custom'
);
12 changes: 12 additions & 0 deletions examples/id-prefix/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './index.scss'

import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
11 changes: 11 additions & 0 deletions examples/id-prefix/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react({
jsxRuntime: 'classic',
}),
],
});
4 changes: 2 additions & 2 deletions packages/react/src/components/IdPrefix/IdPrefix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ automatically generated `id` attributes placed on certain DOM elements.
<Story id="components-idprefix--default" />
</Preview>

This component is used intended to be used in limited cases, primarily only if
you have id conflics when using v10 and v11 packages at the same time during
This component is intended to be used in limited cases, primarily only if
you have id conflicts when using v10 and v11 packages at the same time during
migration.

In React, you can use `IdPrefix` anywhere in your component tree and specify the
Expand Down
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11695,6 +11695,21 @@ __metadata:
languageName: node
linkType: hard

"class-prefix@workspace:examples/class-prefix":
version: 0.0.0-use.local
resolution: "class-prefix@workspace:examples/class-prefix"
dependencies:
"@carbon/react": ^1.24.0
"@types/react": ^18.0.0
"@types/react-dom": ^18.0.0
"@vitejs/plugin-react": 1.1.3
react: ^17.0.0
react-dom: ^17.0.0
sass: ^1.51.0
vite: ^2.9.5
languageName: unknown
linkType: soft

"class-utils@npm:^0.3.5":
version: 0.3.6
resolution: "class-utils@npm:0.3.6"
Expand Down Expand Up @@ -18508,6 +18523,21 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"id-prefix@workspace:examples/id-prefix":
version: 0.0.0-use.local
resolution: "id-prefix@workspace:examples/id-prefix"
dependencies:
"@carbon/react": ^1.24.0
"@types/react": ^18.0.0
"@types/react-dom": ^18.0.0
"@vitejs/plugin-react": 1.1.3
react: ^17.0.0
react-dom: ^17.0.0
sass: ^1.51.0
vite: ^2.9.5
languageName: unknown
linkType: soft

"idb@npm:^6.1.4":
version: 6.1.5
resolution: "idb@npm:6.1.5"
Expand Down