Skip to content

Commit dcba3db

Browse files
committed
feat(eds-core-react): ✨ implement Next (EDS 2.0) architecture with Input component
- Create src/components/next/ folder structure for EDS 2.0 components - Add dual entry points: index.ts (stable) and index.next.ts (next) - Configure subpath exports for @equinor/eds-core-react/next - Migrate Input component to next/ folder with vanilla CSS - Set up centralized CSS bundling in index.css - Add Next (EDS 2.0) section in Storybook with Introduction - Update rollup config for dual builds - Configure Storybook ordering to show Introduction first - Remove old Input.new files - Update CSS_ARCHITECTURE.md documentation
1 parent 9a545d5 commit dcba3db

File tree

19 files changed

+348
-272
lines changed

19 files changed

+348
-272
lines changed

packages/eds-core-react/.storybook/preview.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const preview = {
1919
'Icons',
2020
['Introduction', 'Preview', 'Icon'],
2121
'*',
22+
'Next (EDS 2.0)',
23+
['Introduction', '*'],
2224
'Playground',
2325
],
2426
},

packages/eds-core-react/CSS_ARCHITECTURE.md

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,62 @@
22

33
## Overview
44

5-
Component CSS is centralized in `src/index.css` to prevent duplicate imports and enable automatic tree-shaking.
5+
Next EDS 2.0 components use vanilla CSS with EDS 2.0 tokens. Component CSS is centralized in `src/index.css` to prevent duplicate imports and enable automatic tree-shaking.
6+
7+
**Important:** Only Next EDS 2.0 components (in `src/components/next/`) use vanilla CSS. Stable components use styled-components and don't need CSS files.
68

79
## Structure
810

911
```
1012
src/
11-
├── index.css # Imports all component CSS
12-
├── index.ts # Imports index.css once
13+
├── index.css # Imports all next/ component CSS
14+
├── index.ts # Stable components (no CSS import)
15+
├── index.next.ts # Imports index.css + exports next components
1316
└── components/
14-
└── Input/
15-
├── Input.new.tsx # No CSS import
16-
└── input.new.css # Styles defined here
17+
├── Button/ # Stable component (styled-components)
18+
│ └── Button.tsx
19+
└── next/ # Next EDS 2.0 components (vanilla CSS)
20+
└── Input/
21+
├── Input.tsx # No CSS import
22+
└── input.css # Styles defined here
1723
```
1824

1925
## How It Works
2026

21-
1. Component CSS files contain the styles
22-
2. `src/index.css` imports all component CSS with `@import`
23-
3. `src/index.ts` imports `index.css` once
24-
4. Users get all CSS automatically when importing components
27+
1. Component CSS files contain the styles (e.g., `input.css`)
28+
2. `src/index.css` imports all next/ component CSS with `@import`
29+
3. `src/index.next.ts` imports `index.css` once
30+
4. Users importing from `@equinor/eds-core-react/next` get all CSS automatically
2531

26-
## Adding Components
32+
## Adding Next EDS 2.0 Components
2733

28-
When creating a component with CSS:
34+
When creating a new component in `components/next/`:
2935

30-
1. Create `button.new.css` in component directory
36+
1. Create `input.css` in component directory (lowercase with hyphens)
3137
2. Add to `src/index.css`:
3238
```css
33-
@import './components/Button/button.new.css';
39+
@import './components/next/Input/input.css';
3440
```
3541
3. **Never** import CSS in `.tsx` files
42+
4. Export component from `src/index.next.ts`
3643

3744
## Build
3845

3946
Rollup builds CSS with PostCSS to bundle all `@import` statements:
4047

4148
- **Input**: `src/index.css`
4249
- **Output**:
43-
- `build/index.css` (3.5KB formatted)
44-
- `build/index.min.css` (2.1KB minified)
50+
- `build/index.css` (formatted)
51+
- `build/index.min.css` (minified)
4552

4653
## Usage
4754

48-
Import components normally -- CSS is included automatically:
55+
### Next EDS 2.0 Components
56+
57+
Import from the `/next` subpath -- CSS is included automatically:
4958

5059
```tsx
51-
import { InputNew } from '@equinor/eds-core-react'
60+
import { Input } from '@equinor/eds-core-react/next'
5261
```
5362

5463
Or import CSS separately if needed:
@@ -58,16 +67,40 @@ import '@equinor/eds-core-react/index.css' // Development
5867
import '@equinor/eds-core-react/index.min.css' // Production
5968
```
6069
70+
### Stable Components
71+
72+
Import normally from the main package (no CSS needed):
73+
74+
```tsx
75+
import { Button, Typography } from '@equinor/eds-core-react'
76+
```
77+
6178
## Configuration
6279

6380
**package.json**:
6481

6582
- `"sideEffects": ["**/*.css"]` -- Preserves CSS during tree-shaking
6683
- `"files": ["dist/*", "build/*"]` -- Publishes JS and CSS
67-
- Exports CSS at `./index.css` and `./index.min.css`
84+
- Exports:
85+
- `.` -- Stable components (main package)
86+
- `./next` -- Next EDS 2.0 components (with CSS)
87+
- `./index.css` and `./index.min.css` -- Next component styles
88+
89+
**rollup.config.js**:
90+
91+
Two entry points are built:
92+
93+
1. `src/index.ts``dist/eds-core-react.cjs` (stable components)
94+
2. `src/index.next.ts``dist/next.cjs` (next components with CSS)
6895

6996
**Storybook** (`.storybook/preview.mjs`):
7097

7198
```javascript
72-
import '../src/index.css' // Global component styles
99+
import '../src/index.css' // Next component styles
73100
```
101+
102+
## Naming Conventions
103+
104+
- **CSS files:** lowercase with hyphens (e.g., `input.css`, `text-field.css`)
105+
- **Component files:** PascalCase (e.g., `Input.tsx`, `TextField.tsx`)
106+
- **Folder:** PascalCase matching component name (e.g., `Input/`, `TextField/`)

packages/eds-core-react/build/index.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* Global styles for @equinor/eds-core-react */
2-
3-
/* Component styles */
1+
/* Styles for Next EDS 2.0 Components (vanilla CSS) */
42

53
@layer eds-components {
64
/* Container - use neutral appearance by default */
@@ -68,7 +66,7 @@
6866

6967
/*
7068
* Disabled field - override browser defaults for consistent styling
71-
* Safari applies default opacity and color to disabled inputs, so we need
69+
* Safari applies a default opacity and color to disabled inputs, so we need
7270
* to explicitly set opacity: 1 and use -webkit-text-fill-color
7371
* Note: We don't rely on inherited color context, so this works consistently
7472
*/

packages/eds-core-react/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
"import": "./dist/esm/index.js",
3333
"require": "./dist/eds-core-react.cjs"
3434
},
35+
"./next": {
36+
"types": "./dist/types/index.next.d.ts",
37+
"import": "./dist/esm/index.next.js",
38+
"require": "./dist/next.cjs"
39+
},
3540
"./index.css": "./build/index.css",
3641
"./index.min.css": "./build/index.min.css"
3742
},

packages/eds-core-react/rollup.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,46 @@ export default [
5757
{ file: './dist/eds-core-react.cjs', format: 'cjs', interop: 'auto' },
5858
],
5959
},
60+
{
61+
input: ['./src/index.next.ts'],
62+
external: [
63+
/@babel\/runtime/,
64+
'react/jsx-runtime',
65+
...Object.keys({
66+
...pkg.peerDependencies,
67+
...pkg.dependencies,
68+
}),
69+
],
70+
watch: {
71+
clearScreen: true,
72+
include: ['./src/**', './../tokens/**'],
73+
},
74+
plugins: [
75+
preserveDirective(),
76+
resolve({ extensions }),
77+
commonjs(),
78+
postcss({
79+
extensions: ['.css'],
80+
extract: false,
81+
inject: false,
82+
}),
83+
babel({
84+
babelHelpers: 'runtime',
85+
extensions,
86+
rootMode: 'upward',
87+
}),
88+
],
89+
output: [
90+
{
91+
dir: 'dist/esm',
92+
preserveModules: true,
93+
preserveModulesRoot: 'src',
94+
format: 'es',
95+
sourcemap: isDevelopment,
96+
},
97+
{ file: './dist/next.cjs', format: 'cjs', interop: 'auto' },
98+
],
99+
},
60100
{
61101
input: './src/index.css',
62102
plugins: [

packages/eds-core-react/src/components/Input/Input.new.docs.mdx

Lines changed: 0 additions & 172 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from './Input'
2-
export { Input as InputNew } from './Input.new'

0 commit comments

Comments
 (0)