);
@@ -316,17 +343,20 @@ interface ExtendedTheme extends FusionTheme {
};
}
-const extendedTheme = createTheme({
- app: {
- borderRadius: '12px',
- sidebarWidth: '300px',
+const extendedTheme = createTheme(
+ {
+ app: {
+ borderRadius: '12px',
+ sidebarWidth: '300px',
+ },
},
-}, theme);
+ theme,
+);
// Use in ThemeProvider
-
+;
```
### `StylesProvider`
@@ -334,6 +364,7 @@ const extendedTheme = createTheme({
Creates an isolated styling scope to prevent CSS class name collisions. Critical for micro-frontends and dynamically loaded modules.
**Props:**
+
- `seed`: String prefix for class names (e.g., `"my-module"`)
- `generateClassName`: Optional custom class name generator
- `jss`: Optional custom JSS instance
@@ -420,7 +451,7 @@ function App() {
-
+
@@ -430,6 +461,7 @@ function App() {
```
Even though both modules use the same styles object, they'll generate different class names:
+
- Module A: `module-a-makeStyles-root-1`
- Module B: `module-b-makeStyles-root-1`
@@ -440,26 +472,29 @@ Full support for CSS-in-JS nested selectors:
```tsx
import { clsx } from '@equinor/fusion-react-styles';
-const useStyles = makeStyles({
- root: {
- color: 'blue',
- '&:hover': {
- color: 'red',
- },
- '& .child': {
- padding: '10px',
- },
- '&$disabled': {
- opacity: 0.5,
+const useStyles = makeStyles(
+ {
+ root: {
+ color: 'blue',
+ '&:hover': {
+ color: 'red',
+ },
+ '& .child': {
+ padding: '10px',
+ },
+ '&$disabled': {
+ opacity: 0.5,
+ },
},
+ disabled: {},
},
- disabled: {},
-}, { name: 'NestedComponent' });
+ { name: 'NestedComponent' },
+);
function Component() {
const classes = useStyles();
const [disabled, setDisabled] = useState(false);
-
+
return (
Child element
@@ -479,16 +514,17 @@ interface StyleProps {
color: string;
}
-const useStyles = makeStyles((themeValue) =>
- createStyles({
- root: (props: StyleProps) => ({
- ...themeValue.typography.paragraph.body_short.style,
- color: props.color,
- padding: themeValue.spacing.comfortable.medium.getVariable('padding'),
- backgroundColor: themeValue.colors.ui.background__default.getVariable('color'),
+const useStyles = makeStyles(
+ (themeValue) =>
+ createStyles({
+ root: (props: StyleProps) => ({
+ ...themeValue.typography.paragraph.body_short.style,
+ color: props.color,
+ padding: themeValue.spacing.comfortable.medium.getVariable('padding'),
+ backgroundColor: themeValue.colors.ui.background__default.getVariable('color'),
+ }),
}),
- }),
- { name: 'MyComponent' }
+ { name: 'MyComponent' },
);
function Component(props: StyleProps) {
@@ -520,14 +556,15 @@ const extendedTheme = createTheme({
});
// Use extended theme with makeStyles
-const useStyles = makeStyles((themeValue: typeof extendedTheme) =>
- createStyles({
- root: {
- borderRadius: themeValue.app.borderRadius,
- padding: themeValue.spacing.comfortable.medium.getVariable('padding'),
- },
- }),
- { name: 'ExtendedThemeComponent' }
+const useStyles = makeStyles(
+ (themeValue: typeof extendedTheme) =>
+ createStyles({
+ root: {
+ borderRadius: themeValue.app.borderRadius,
+ padding: themeValue.spacing.comfortable.medium.getVariable('padding'),
+ },
+ }),
+ { name: 'ExtendedThemeComponent' },
);
```
@@ -541,23 +578,27 @@ Type inference works automatically, and using `createStyles` provides even bette
```tsx
// Basic type inference - works, but ClassKey is inferred as string
-const useStyles = makeStyles({
- root: { color: 'red' },
- button: { padding: '10px' },
-}, { name: 'Component' });
+const useStyles = makeStyles(
+ {
+ root: { color: 'red' },
+ button: { padding: '10px' },
+ },
+ { name: 'Component' },
+);
const classes = useStyles(); // classes: Record
// With createStyles - ClassKey is inferred as literal union type
-const useStyles = makeStyles((theme) =>
- createStyles({
- root: {
- color: theme.colors.text.static_icons__default.getVariable('color'),
- },
- button: {
- padding: theme.spacing.comfortable.medium.getVariable('padding'),
- },
- }),
- { name: 'Component' }
+const useStyles = makeStyles(
+ (theme) =>
+ createStyles({
+ root: {
+ color: theme.colors.text.static_icons__default.getVariable('color'),
+ },
+ button: {
+ padding: theme.spacing.comfortable.medium.getVariable('padding'),
+ },
+ }),
+ { name: 'Component' },
);
const classes = useStyles(); // classes: Record<'root' | 'button', string>
// TypeScript will error if you try to access classes.foo - it knows the exact keys!
@@ -574,12 +615,15 @@ interface MyAppTheme extends StyleDefinition {
customProperty: string;
}
-const useStyles = makeStyles((theme: FusionTheme) => ({
- root: {
- color: theme.colors.text.static_icons__default.getVariable('color'),
- custom: theme.customProperty, // Fully typed!
- },
-}), { name: 'Component' });
+const useStyles = makeStyles(
+ (theme: FusionTheme) => ({
+ root: {
+ color: theme.colors.text.static_icons__default.getVariable('color'),
+ custom: theme.customProperty, // Fully typed!
+ },
+ }),
+ { name: 'Component' },
+);
```
### Type-Safe Class Access
diff --git a/packages/styles/src/__tests__/README.md b/packages/styles/src/__tests__/README.md
index 4e2bd430c..926601d9e 100644
--- a/packages/styles/src/__tests__/README.md
+++ b/packages/styles/src/__tests__/README.md
@@ -1,40 +1,38 @@
-/**
- * @fileoverview Test Suite for @equinor/fusion-react-styles
- *
- * This test suite demonstrates what this package does and how it works.
- * By reading these tests, you can understand:
- *
- * 1. **makeStyles** - The main API for creating styled components
- * - Converts JavaScript style objects into CSS class names
- * - Supports dynamic styles based on props and theme
- * - Caches stylesheets for performance
- *
- * 2. **StylesProvider** - Creates isolated styling scopes
- * - Prevents CSS class name collisions between modules
- * - Critical for micro-frontends and dynamically loaded components
- * - Uses "seed" prefixes to create unique namespaces
- *
- * 3. **ThemeProvider** - Provides theme values to components
- * - Enables design system theming
- * - Supports theme composition (nested themes)
- * - Integrates with fwc-theme web component
- *
- * 4. **Utilities** - Supporting functions
- * - createGenerateClassName: Creates class name generators
- * - createStyles: Type-safe style helper
- * - theme: Fusion design system theme
- *
- * KEY FEATURE: Style Isolation
- * When you have nested StylesProviders with different seeds, they generate
- * different class names even if they use the same styles. This prevents
- * CSS collisions - critical for modular applications.
- *
- * Example:
- * - Module A with seed "moduleA" using style "root" â "moduleA-makeStyles-root-1"
- * - Module B with seed "moduleB" using style "root" â "moduleB-makeStyles-root-1"
- * - No collision! Each module gets its own CSS.
- */
-
-// This file exists to document the test structure
-// Actual tests are in individual test files
+# Test Suite for @equinor/fusion-react-styles
+This test suite demonstrates what this package does and how it works.
+By reading these tests, you can understand:
+
+1. **makeStyles** - The main API for creating styled components
+ - Converts JavaScript style objects into CSS class names
+ - Supports dynamic styles based on props and theme
+ - Caches stylesheets for performance
+
+2. **StylesProvider** - Creates isolated styling scopes
+ - Prevents CSS class name collisions between modules
+ - Critical for micro-frontends and dynamically loaded components
+ - Uses "seed" prefixes to create unique namespaces
+
+3. **ThemeProvider** - Provides theme values to components
+ - Enables design system theming
+ - Supports theme composition (nested themes)
+ - Integrates with fwc-theme web component
+
+4. **Utilities** - Supporting functions
+ - createGenerateClassName: Creates class name generators
+ - createStyles: Type-safe style helper
+ - theme: Fusion design system theme
+
+## Key feature: Style isolation
+
+When you have nested StylesProviders with different seeds, they generate
+different class names even if they use the same styles. This prevents
+CSS collisions - critical for modular applications.
+
+Example:
+
+- Module A with seed "moduleA" using style "root" â "moduleA-makeStyles-root-1"
+- Module B with seed "moduleB" using style "root" â "moduleB-makeStyles-root-1"
+- No collision! Each module gets its own CSS.
+
+This file documents the test structure. The actual tests are in the individual test files.
diff --git a/packages/styles/src/__tests__/StyleProvider.test.tsx b/packages/styles/src/__tests__/StyleProvider.test.tsx
index d8e6fa8eb..85f2040c1 100644
--- a/packages/styles/src/__tests__/StyleProvider.test.tsx
+++ b/packages/styles/src/__tests__/StyleProvider.test.tsx
@@ -53,6 +53,7 @@ describe('StylesProvider - Styling scope isolation', () => {
// WHAT: StylesProvider provides JSS instance and class name generator via context
// WHY: Child components need this to generate styles
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const context = useContext(StylesContext);
// Verify context has all required properties
@@ -75,6 +76,7 @@ describe('StylesProvider - Styling scope isolation', () => {
const customGenerate = createGenerateClassName('custom');
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const context = useContext(StylesContext);
// Verify custom generator is used
@@ -94,6 +96,7 @@ describe('StylesProvider - Styling scope isolation', () => {
// WHY: Critical for preventing CSS collisions when modules share same style names
// EXAMPLE: Module A and Module B both use "root" class - with seeds they become "moduleA-root-1" and "moduleB-root-1"
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const context = useContext(StylesContext);
const className = context.generateClassName({ key: 'test' });
@@ -116,6 +119,7 @@ describe('StylesProvider - Styling scope isolation', () => {
const { create } = await import('jss');
const customJss = create();
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const context = useContext(StylesContext);
// Verify custom JSS instance is used
@@ -137,6 +141,7 @@ describe('StylesProvider - Styling scope isolation', () => {
const parentGenerate = createGenerateClassName('parent');
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const context = useContext(StylesContext);
// Child inherits parent's generator
@@ -159,6 +164,7 @@ describe('StylesProvider - Styling scope isolation', () => {
const customSheetsManager = new Map();
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const context = useContext(StylesContext);
// Verify custom manager is used
@@ -193,6 +199,7 @@ describe('StylesProvider - Styling scope isolation', () => {
const useStyles1 = makeStyles(sharedStyles, { name: 'Component1' });
const useStyles2 = makeStyles(sharedStyles, { name: 'Component2' });
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const Component1 = () => {
const classes = useStyles1({});
return (
@@ -202,6 +209,7 @@ describe('StylesProvider - Styling scope isolation', () => {
);
};
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const Component2 = () => {
const classes = useStyles2({});
return (
@@ -266,6 +274,7 @@ describe('StylesProvider - Styling scope isolation', () => {
const useOuterStyles = makeStyles(styles, { name: 'OuterComponent' });
const useInnerStyles = makeStyles(styles, { name: 'InnerComponent' });
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const InnerComponent = () => {
const classes = useInnerStyles({});
return (
@@ -275,6 +284,7 @@ describe('StylesProvider - Styling scope isolation', () => {
);
};
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const OuterComponent = () => {
const classes = useOuterStyles({});
return (
@@ -336,6 +346,7 @@ describe('StylesProvider - Styling scope isolation', () => {
const useBaseStyles = makeStyles(baseStyles, { name: 'BaseComponent' });
const useDynamicStyles = makeStyles(baseStyles, { name: 'DynamicComponent' });
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const BaseComponent = () => {
const classes = useBaseStyles({});
return (
@@ -350,6 +361,7 @@ describe('StylesProvider - Styling scope isolation', () => {
);
};
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const DynamicComponent = () => {
const classes = useDynamicStyles({});
return (
diff --git a/packages/styles/src/__tests__/ThemeProvider.test.tsx b/packages/styles/src/__tests__/ThemeProvider.test.tsx
index 9b9734905..43861c01e 100644
--- a/packages/styles/src/__tests__/ThemeProvider.test.tsx
+++ b/packages/styles/src/__tests__/ThemeProvider.test.tsx
@@ -50,6 +50,7 @@ describe('ThemeProvider - Theme distribution', () => {
// WHY: Allows components to use theme values without receiving theme as prop
// EXAMPLE: Component uses theme.colors.primary instead of hardcoded color
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const theme = useContext(ThemeContext);
// Verify theme from provider is available
@@ -69,6 +70,7 @@ describe('ThemeProvider - Theme distribution', () => {
// WHY: Components still work even if parent doesn't provide theme
// EXAMPLE: Standalone components or utility components
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const theme = useContext(ThemeContext);
// Verify default theme is used
@@ -107,6 +109,7 @@ describe('ThemeProvider - Theme distribution', () => {
{ name: 'ThemeFunctionTest' },
);
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const classes = useStyles({});
return
Test
;
@@ -159,6 +162,7 @@ describe('ThemeProvider - Theme distribution', () => {
);
};
+ // biome-ignore lint/correctness/noComponentHookFactories: test fixture closes over per-test values
const TestComponent = () => {
const componentTheme = useTheme();
// Verify the merged theme is available
diff --git a/packages/styles/src/make-styles.ts b/packages/styles/src/make-styles.ts
index aed8dfbb5..1bf0f80bb 100644
--- a/packages/styles/src/make-styles.ts
+++ b/packages/styles/src/make-styles.ts
@@ -144,6 +144,7 @@ export function makeStyles<
const instanceName = generateInstanceName(name);
+ // biome-ignore lint/correctness/noComponentHookFactories: makeStyles is a public hook factory, called once at module level by consumers
const useStyles = (props: Props = {} as Props): Record => {
// Get theme from context or use default
const theme = useContext(ThemeContext) || optionsDefaultTheme;
diff --git a/packages/tabs/README.md b/packages/tabs/README.md
index b3d3791df..dd9bd7950 100644
--- a/packages/tabs/README.md
+++ b/packages/tabs/README.md
@@ -9,17 +9,21 @@ This package provides a simple tab router. It handles active tab state, and rend
- **State Management**: Uses `@equinor/fusion-observable` for state management and actions.
- **Context API**: Provides a context for accessing and manipulating router state.
-
## Usage
```tsx
-import { TabProvider } from '@equinor/fusion-react-components-tabs';
+import { TabProvider } from '@equinor/fusion-react-components-tabs';
const MyComponent = () => (
-
- Tab 1 content
- Tab 2 content
-
+
+
+ {' '}
+ Tab 1 content
+
+
+ {' '}
+ Tab 2 content
+
+
);
```
-
diff --git a/packages/textarea/README.md b/packages/textarea/README.md
index bcf68f75e..959e3faba 100644
--- a/packages/textarea/README.md
+++ b/packages/textarea/README.md
@@ -8,6 +8,7 @@
[Fusion Web Component](https://github.com/equinor/fusion-web-components/tree/main/packages/textarea)
### Installation
+
```sh
npm install @equinor/fusion-react-textarea
```
@@ -15,49 +16,63 @@ npm install @equinor/fusion-react-textarea
### Example Usage
```tsx
-
+;
```
### Properties/Attributes
-Name | Type | Description
-------------------------- | ----------------------------- | -----------
-`value` | `string` | The input control's value.
-`type` | `TextInputType*` | A string specifying the type of control to render.
-`variant` | `TextInputVariant**` | Input style variant to render.
-`label` | `string` | Sets floating label value.
-`rows` | `number` | Sets number of visible text lines.
-`cols` | `number` | Sets the visible width of the textarea.
-`placeholder` | `string` | Sets disappearing input placeholder.
-`prefix` | `string` | Prefix text to display before the input.
-`suffix` | `string` | Suffix text to display after the input.
-`disabled` | `boolean` | Whether or not the input should be disabled.
-`charCounter` | `boolean | TextInputCharCounter***` | **Note: requries `maxLength` to be set.** Display character counter with max length.
-`helper` | `string` | Helper text to display below the input. Display default only when focused.
-`helperPersistent` | `boolean` | Always show the helper text despite focus.
-`required` | `boolean` | Displays error state if value is empty and input is blurred.
-`maxLength` | `number` | Maximum length to accept input.
-`validationMessage` | `string` | Message to show in the error color when the textarea is invalid. (Helper text will not be visible)
-`pattern` | `string` | [`HTMLInputElement.prototype.pattern`](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes) (empty string will unset attribute)
-`min` | `number`\|`string` | [`HTMLInputElement.prototype.min`](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes) (empty string will unset attribute)
-`max` | `number`\|`string` | [`HTMLInputElement.prototype.max`](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes) (empty string will unset attribute)
-`size` | `number`\|`null` | [`HTMLInputElement.prototype.size`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefsize) (null will unset attribute)
-`step` | `number`\|`null` | [`HTMLInputElement.prototype.step`](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes) (null will unset attribute)
-`autoValidate` | `boolean` | Reports validity on value change rather than only on blur.
-`validity` | `ValidityState` (readonly) | The [`ValidityState`](https://developer.mozilla.org/en-US/docs/Web/API/ValidityState) of the textarea.
-`willValidate` | `boolean` (readonly) | [`HTMLInputElement.prototype.willValidate`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#Properties)
-`validityTransform` | `ValidityTransform****`\|`null` | Callback called before each validation check. See the [validation section](#Validation) for more details.
-`validateOnInitialRender` | `boolean` | Runs validation check on initial render.
-`name` | `string` | Sets the `name` attribute on the internal input.\*\*\*
-
-\* `TextInputType` is exported by `TextArea`.
+| Name | Type | Description |
+| ------------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `value` | `string` | The input control's value. |
+| `type` | `TextInputType*` | A string specifying the type of control to render. |
+| `variant` | `TextInputVariant**` | Input style variant to render. |
+| `label` | `string` | Sets floating label value. |
+| `rows` | `number` | Sets number of visible text lines. |
+| `cols` | `number` | Sets the visible width of the textarea. |
+| `placeholder` | `string` | Sets disappearing input placeholder. |
+| `prefix` | `string` | Prefix text to display before the input. |
+| `suffix` | `string` | Suffix text to display after the input. |
+| `disabled` | `boolean` | Whether or not the input should be disabled. |
+| `charCounter` | `boolean | TextInputCharCounter***` | **Note: requries `maxLength` to be set.** Display character counter with max length. |
+| `helper` | `string` | Helper text to display below the input. Display default only when focused. |
+| `helperPersistent` | `boolean` | Always show the helper text despite focus. |
+| `required` | `boolean` | Displays error state if value is empty and input is blurred. |
+| `maxLength` | `number` | Maximum length to accept input. |
+| `validationMessage` | `string` | Message to show in the error color when the textarea is invalid. (Helper text will not be visible) |
+| `pattern` | `string` | [`HTMLInputElement.prototype.pattern`](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes) (empty string will unset attribute) |
+| `min` | `number`\|`string` | [`HTMLInputElement.prototype.min`](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes) (empty string will unset attribute) |
+| `max` | `number`\|`string` | [`HTMLInputElement.prototype.max`](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes) (empty string will unset attribute) |
+| `size` | `number`\|`null` | [`HTMLInputElement.prototype.size`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefsize) (null will unset attribute) |
+| `step` | `number`\|`null` | [`HTMLInputElement.prototype.step`](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Validation-related_attributes) (null will unset attribute) |
+| `autoValidate` | `boolean` | Reports validity on value change rather than only on blur. |
+| `validity` | `ValidityState` (readonly) | The [`ValidityState`](https://developer.mozilla.org/en-US/docs/Web/API/ValidityState) of the textarea. |
+| `willValidate` | `boolean` (readonly) | [`HTMLInputElement.prototype.willValidate`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#Properties) |
+| `validityTransform` | `ValidityTransform****`\|`null` | Callback called before each validation check. See the [validation section](#Validation) for more details. |
+| `validateOnInitialRender` | `boolean` | Runs validation check on initial render. |
+| `name` | `string` | Sets the `name` attribute on the internal input.\*\*\* |
+
+\* `TextInputType` is exported by `TextArea`.
```ts
-type TextInputType = 'text'|'search'|'tel'|'url'|'email'|'password'|
- 'date'|'month'|'week'|'time'|'datetime-local'|'number'|'color';
+type TextInputType =
+ | 'text'
+ | 'search'
+ | 'tel'
+ | 'url'
+ | 'email'
+ | 'password'
+ | 'date'
+ | 'month'
+ | 'week'
+ | 'time'
+ | 'datetime-local'
+ | 'number'
+ | 'color';
```
-\*\* `TextInputVariant` is exported by `TextArea`.
+\*\* `TextInputVariant` is exported by `TextArea`.
```ts
export type TextInputVariant = 'filled' | 'outlined';
@@ -72,42 +87,42 @@ type TextInputCharCounter = 'external' | 'internal';
\*\*\*\* `ValidityTransform` is exported by `TextArea`.
```ts
-type ValidityTransform = (value: string, nativeValidity: ValidityState) => Partial
+type ValidityTransform = (value: string, nativeValidity: ValidityState) => Partial;
```
\*\*\*\*\* The `name` property should only be used for browser autofill as webcomponent form participation does not currently consider the `name` attribute. See [#289](https://github.com/material-components/material-components-web-components/issues/289).
### Methods
-| Name | Description
-| -------- | -------------
-| `checkValidity() => boolean` | Returns `true` if the textarea passes validity checks. Returns `false` and fires an [`invalid`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/invalid_event) event on the textarea otherwise. **NOTE:** When accessing any property or function that checks validity at textarea initial boot up, you may have to await `