-
Notifications
You must be signed in to change notification settings - Fork 70
chore: update documentation for project guidelines and standards #4270
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
Changes from all commits
2347d88
7911c1d
0527b5f
3b28907
9958ee6
cc57b20
cf5ecb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,24 @@ | ||
| # GitHub Copilot Instructions for Equinor Design System | ||
|
|
||
| ## Project Overview | ||
| ## Overview | ||
|
|
||
| This monorepo contains Equinor's Design System (EDS) - a component library and design tokens that implement Equinor's design language. The design system consists of multiple packages: | ||
| Equinor Design System (EDS) is a monorepo with component libraries and design tokens implementing Equinor's design language. | ||
|
|
||
| - `@equinor/eds-core-react`: Core React components | ||
| - `@equinor/eds-tokens`: Design tokens and variables | ||
| - `@equinor/eds-icons`: Icon library | ||
| - `@equinor/eds-lab-react`: Experimental components | ||
| - `@equinor/eds-data-grid-react`: Data grid component | ||
| ## Packages | ||
|
|
||
| ## Code Style & Patterns | ||
| - **`@equinor/eds-core-react`** - Main React component library (most development happens here) | ||
| - **`@equinor/eds-tokens`** - Design tokens, CSS variables, and theming | ||
| - **`@equinor/eds-icons`** - Icon library | ||
| - **`@equinor/eds-lab-react`** - Experimental/WIP components | ||
| - **`@equinor/eds-data-grid-react`** - Data grid component | ||
|
|
||
| Apply detailed guidelines from: | ||
| ## Guidelines | ||
|
|
||
| - [Global coding standards](./instructions/global-coding.instructions.md) | ||
| - [TypeScript guidelines](./instructions/ts.instructions.md) | ||
| - [React guidelines](./instructions/react.instructions.md) | ||
| - [Styling guidelines](./instructions/styling.instructions.md) | ||
| - [Figma component creation](./instructions/figma.instructions.md) | ||
| - [Markdown guidelines](./instructions/markdown.instructions.md) | ||
| - [Global standards](./instructions/global-coding.instructions.md) - Accessibility, naming, exports | ||
| - [TypeScript](./instructions/ts.instructions.md) - Type patterns and testing | ||
| - [React](./instructions/react.instructions.md) - Components, hooks, file structure | ||
| - [Styling](./instructions/styling.instructions.md) - CSS, BEM, responsive design | ||
| - [Figma](./instructions/figma.instructions.md) - Design-to-code workflow | ||
| - [Markdown](./instructions/markdown.instructions.md) - Documentation format | ||
|
|
||
| ### Color System | ||
|
|
||
| The <abbr title="Equinor Design System">EDS</abbr> provides two color approaches. Choose one and use it consistently: | ||
|
|
||
| - [Color System Introduction](../packages/eds-tokens/instructions/colors.md) -- Overview of semantic categories, approaches, and accessibility | ||
| - [Static Color Approach](../packages/eds-tokens/instructions/colors-static.md) -- Explicit semantic variables for fixed meanings | ||
| - [Dynamic Color Approach](../packages/eds-tokens/instructions/colors-dynamic.md) -- Abstract role variables with runtime appearance switching | ||
|
|
||
| ## Testing Requirements | ||
|
|
||
| - All components and features should be thoroughly tested | ||
| - All components should have appropriate unit tests using Jest | ||
| - Visual regression tests should be included where applicable | ||
| - Test accessibility features explicitly | ||
| - Include test cases for edge cases and error states | ||
|
|
||
| ## Documentation | ||
|
|
||
| - All components should have Storybook stories | ||
| - Include usage examples in documentation | ||
| - Document all props, including types and default values | ||
| - Add information about accessibility features | ||
| - Provide guidance on common patterns and implementation details | ||
|
|
||
| ## PR and Code Review Process | ||
|
|
||
| - Use conventional commits for commit messages | ||
| - PRs should include tests and documentation | ||
| - Link relevant Figma designs when applicable | ||
| - Ensure changes pass all CI checks | ||
| For color systems: See `packages/eds-tokens/instructions/colors.md` |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,26 +2,75 @@ | |||||||||||||||||
| applyTo: '**/*.ts,**/*.tsx' | ||||||||||||||||||
| --- | ||||||||||||||||||
|
|
||||||||||||||||||
| # Project coding standards for React | ||||||||||||||||||
|
|
||||||||||||||||||
| ## React Guidelines | ||||||||||||||||||
|
|
||||||||||||||||||
| - It is not necessary to import React in every file. | ||||||||||||||||||
| - Use functional components with hooks | ||||||||||||||||||
| - Follow the React hooks rules (no conditional hooks) | ||||||||||||||||||
| - Use React.FC type for components with children | ||||||||||||||||||
| - Components should be composable | ||||||||||||||||||
| - Implement proper error boundaries | ||||||||||||||||||
| - Always implement proper keyboard navigation and focus management | ||||||||||||||||||
| - Every component must support proper ARIA attributes | ||||||||||||||||||
| - A component directory should be capitalized and named after the component | ||||||||||||||||||
| - Keep component style and script as simple and small as possible. | ||||||||||||||||||
| - A component should have these files in its directory: | ||||||||||||||||||
| - Component.tsx | ||||||||||||||||||
| - Component.types.ts | ||||||||||||||||||
| - Component.css | ||||||||||||||||||
| - Component.test.tsx | ||||||||||||||||||
| - Component.stories.tsx | ||||||||||||||||||
| - Use `index.ts` to export the component | ||||||||||||||||||
| - Define helper functions outside the component but in the module scope | ||||||||||||||||||
| - If a component with the same name already exists, create a new component with suffix `.new` (e.g. `Button.new.tsx`) and ensure it is not used in the codebase | ||||||||||||||||||
| # React Guidelines | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Component Structure | ||||||||||||||||||
|
|
||||||||||||||||||
| **File organization (required):** | ||||||||||||||||||
|
|
||||||||||||||||||
| ``` | ||||||||||||||||||
| MyComponent/ | ||||||||||||||||||
| index.ts # Export only | ||||||||||||||||||
| MyComponent.tsx # Component implementation | ||||||||||||||||||
| MyComponent.types.ts # Props and type definitions | ||||||||||||||||||
| my-component.css # Styles (vanilla CSS, BEM) | ||||||||||||||||||
| MyComponent.test.tsx # Unit tests (Jest + Testing Library) | ||||||||||||||||||
| MyComponent.stories.tsx # Storybook documentation | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| **Directory naming:** PascalCase matching component name | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Implementation Patterns | ||||||||||||||||||
|
|
||||||||||||||||||
| **Functional components with hooks:** | ||||||||||||||||||
|
|
||||||||||||||||||
| ```typescript | ||||||||||||||||||
| import { MyComponentProps } from './MyComponent.types'; | ||||||||||||||||||
| import './my-component.css'; | ||||||||||||||||||
|
Comment on lines
+28
to
+29
|
||||||||||||||||||
|
|
||||||||||||||||||
| export const MyComponent: React.FC<MyComponentProps> = ({ | ||||||||||||||||||
| children, | ||||||||||||||||||
| variant = 'default', | ||||||||||||||||||
| ...props | ||||||||||||||||||
| }) => { | ||||||||||||||||||
| return ( | ||||||||||||||||||
| <div className="my-component" {...props}> | ||||||||||||||||||
| {children} | ||||||||||||||||||
| </div> | ||||||||||||||||||
| ); | ||||||||||||||||||
| }; | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
Comment on lines
+31
to
+42
|
||||||||||||||||||
|
|
||||||||||||||||||
| **Rules:** | ||||||||||||||||||
|
|
||||||||||||||||||
| - No conditional hooks (move into separate components if needed) | ||||||||||||||||||
| - No React import needed (no JSX pragma in modern React) | ||||||||||||||||||
|
||||||||||||||||||
| - No React import needed (no JSX pragma in modern React) | |
| - For files using JSX with React 17+ and the new JSX transform, no React import is needed. | |
| For non-JSX usage (e.g., using React APIs directly), you still need to import React. | |
| Example (JSX, no import needed): | |
| ```typescript | |
| // React 17+ with new JSX transform | |
| export const MyComponent = () => <div>Hello</div>; |
Example (non-JSX, import needed):
import * as React from 'react';
// Using React.createElement directly
export const MyComponent = () => React.createElement('div', null, 'Hello');| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,86 @@ | |
| applyTo: '**' | ||
| --- | ||
|
|
||
| ## Styling Guidelines | ||
|
|
||
| - Use vanilla CSS | ||
| - Ensure responsive design | ||
| - Use CSS variables for theming and consistent styles | ||
| - Use BEM (Block Element Modifier) naming convention for CSS classes | ||
| - Avoid inline styles in JSX | ||
| - Do not use CSS-in-JS libraries like styled-components or emotion | ||
| - The css file name should be named after the component but lowercase and use hyphens as separators (e.g. TextInput becomes `text-input.css`). | ||
| - The selector name should be named after the component but lowercase and use hyphens as separators (e.g. TextInput becomes `.text-input`. | ||
| # Styling Guidelines | ||
|
|
||
| ## Tech Stack | ||
|
|
||
| - **Use:** Vanilla CSS only | ||
| - **Avoid:** CSS-in-JS (styled-components, emotion), Tailwind inline classes | ||
| - **Variables:** CSS custom properties from `@equinor/eds-tokens` | ||
| - **Responsive:** Mobile-first approach with media queries | ||
|
|
||
| ## Naming Conventions | ||
|
|
||
| **Files:** Component name in lowercase with hyphens | ||
|
|
||
| ``` | ||
| TextInput.tsx → text-input.css | ||
| DataGrid.tsx → data-grid.css | ||
| ``` | ||
|
|
||
| **Classes:** BEM format with block as component name | ||
|
|
||
| ```css | ||
| .text-input { | ||
| /* block */ | ||
| } | ||
| .text-input__label { | ||
| /* element */ | ||
| } | ||
| .text-input__input { | ||
| /* element */ | ||
| } | ||
| .text-input--disabled { | ||
| /* modifier */ | ||
| } | ||
| .text-input--error { | ||
| /* modifier */ | ||
| } | ||
| ``` | ||
|
|
||
| ## Patterns | ||
|
|
||
| **CSS Variables (from EDS tokens):** | ||
|
|
||
| ```css | ||
| .text-input { | ||
| color: var(--eds-color-text-strong); | ||
| background: var(--eds-color-bg-input); | ||
| border: 1px solid var(--eds-color-border-medium); | ||
| } | ||
|
Comment on lines
+49
to
+52
|
||
| ``` | ||
|
|
||
| **Responsive Design:** | ||
|
|
||
| ```css | ||
| .button { | ||
| padding: 0.5rem 1rem; | ||
| } | ||
|
|
||
| @media (min-width: 768px) { | ||
| .button { | ||
| padding: 0.75rem 1.5rem; | ||
| } | ||
|
Comment on lines
+59
to
+65
|
||
| } | ||
| ``` | ||
|
|
||
| **Avoid:** | ||
|
|
||
| ```jsx | ||
| // ❌ No inline styles | ||
| <div style={{ color: 'red' }}> | ||
pomfrida marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // ❌ No CSS-in-JS | ||
| const StyledDiv = styled.div`...`; | ||
pomfrida marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // ✅ Use CSS class | ||
| <div className="button"> | ||
| ``` | ||
|
|
||
| ## Best Practices | ||
|
|
||
| - Single responsibility per CSS file | ||
| - Reuse tokens instead of hardcoding colors/sizes | ||
| - Test responsive breakpoints | ||
| - Ensure theme compatibility (light/dark modes) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolons in export and import examples. For consistency with TypeScript best practices, add semicolons after each statement.