@equinor/eds-core-react 2.3.1-beta.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,39 @@
1
- import { useContext, createContext } from 'react';
2
- import 'react/jsx-runtime';
1
+ import { useContext, useState, useEffect, createContext } from 'react';
2
+ import { jsx } from 'react/jsx-runtime';
3
3
 
4
4
  const initalState = {
5
5
  /** Density for all components inside `EdsProvider` */
6
6
  density: 'comfortable'
7
7
  };
8
8
  const EdsContext = /*#__PURE__*/createContext(initalState);
9
+ const EdsProvider = ({
10
+ children,
11
+ density,
12
+ rootElement
13
+ }) => {
14
+ const [state, setState] = useState({
15
+ ...initalState,
16
+ density: density || 'comfortable'
17
+ });
18
+ const setDensity = density => setState(prevState => ({
19
+ ...prevState,
20
+ density
21
+ }));
22
+ useEffect(() => {
23
+ if (typeof density !== 'undefined' && density !== state.density) {
24
+ setDensity(density);
25
+ }
26
+ }, [density, state.density]);
27
+ const value = {
28
+ density: state.density,
29
+ rootElement,
30
+ setDensity
31
+ };
32
+ return /*#__PURE__*/jsx(EdsContext.Provider, {
33
+ value: value,
34
+ children: children
35
+ });
36
+ };
9
37
  const useEds = () => useContext(EdsContext);
10
38
 
11
- export { useEds };
39
+ export { EdsProvider, useEds };
@@ -0,0 +1,11 @@
1
+ import { useContext, createContext } from 'react';
2
+ import 'react/jsx-runtime';
3
+
4
+ const initalState = {
5
+ /** Density for all components inside `EdsProvider` */
6
+ density: 'comfortable'
7
+ };
8
+ const EdsContext = /*#__PURE__*/createContext(initalState);
9
+ const useEds = () => useContext(EdsContext);
10
+
11
+ export { useEds };
@@ -0,0 +1,152 @@
1
+ import { forwardRef, useRef, useState, useMemo, useEffect, cloneElement } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import styled from 'styled-components';
4
+ import { mergeRefs, typographyTemplate, spacingsTemplate, bordersTemplate } from '@equinor/eds-utils';
5
+ import { tooltip } from './Tooltip.tokens.js';
6
+ import { useFloating, autoUpdate, offset, flip, shift, arrow, useInteractions, useHover, useFocus, useRole, useDismiss } from '@floating-ui/react';
7
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
8
+ import { useEds } from '../EdsProvider/eds.context.js';
9
+
10
+ const StyledTooltip = styled('div').withConfig({
11
+ shouldForwardProp: () => true //workaround to avoid warning until popover gets added to react types
12
+ }).withConfig({
13
+ displayName: "Tooltip__StyledTooltip",
14
+ componentId: "sc-m2im2p-0"
15
+ })(["inset:unset;border:0;overflow:visible;", " ", " ", " background:", ";white-space:nowrap;&::before{content:'; Has tooltip: ';clip-path:inset(50%);height:1px;width:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;}&::backdrop{background-color:transparent;}"], typographyTemplate(tooltip.typography), spacingsTemplate(tooltip.spacings), bordersTemplate(tooltip.border), tooltip.background);
16
+ const ArrowWrapper = styled.div.withConfig({
17
+ displayName: "Tooltip__ArrowWrapper",
18
+ componentId: "sc-m2im2p-1"
19
+ })(["position:absolute;width:", ";height:", ";z-index:-1;"], tooltip.entities.arrow.width, tooltip.entities.arrow.height);
20
+ const TooltipArrow = styled.svg.withConfig({
21
+ displayName: "Tooltip__TooltipArrow",
22
+ componentId: "sc-m2im2p-2"
23
+ })(["width:", ";height:", ";position:absolute;fill:", ";"], tooltip.entities.arrow.width, tooltip.entities.arrow.height, tooltip.background);
24
+ const Tooltip = /*#__PURE__*/forwardRef(function Tooltip({
25
+ title,
26
+ placement = 'bottom',
27
+ children,
28
+ style,
29
+ enterDelay = 100,
30
+ disabled = false,
31
+ portalContainer,
32
+ ...rest
33
+ }, ref) {
34
+ const arrowRef = useRef(null);
35
+ const [open, setOpen] = useState(false);
36
+ const {
37
+ rootElement
38
+ } = useEds();
39
+ const shouldOpen = Boolean(title) && typeof document !== 'undefined';
40
+ const {
41
+ x,
42
+ y,
43
+ refs,
44
+ strategy,
45
+ context,
46
+ middlewareData: {
47
+ arrow: {
48
+ x: arrowX,
49
+ y: arrowY
50
+ } = {}
51
+ },
52
+ placement: finalPlacement,
53
+ elements
54
+ } = useFloating({
55
+ placement,
56
+ open,
57
+ onOpenChange: setOpen,
58
+ middleware: [offset(14), flip(), shift({
59
+ padding: 8
60
+ }), arrow({
61
+ element: arrowRef
62
+ })],
63
+ whileElementsMounted: autoUpdate
64
+ });
65
+ const mergedAnchorRef = useMemo(() => mergeRefs(refs.setReference), [refs.setReference]);
66
+ const tooltipRef = useMemo(() => mergeRefs(refs.setFloating, ref), [refs.setFloating, ref]);
67
+ const {
68
+ getReferenceProps,
69
+ getFloatingProps
70
+ } = useInteractions([useHover(context, {
71
+ delay: {
72
+ open: enterDelay
73
+ }
74
+ }), useFocus(context), useRole(context, {
75
+ role: 'tooltip'
76
+ }), useDismiss(context)]);
77
+ useEffect(() => {
78
+ const staticSide = {
79
+ top: 'bottom',
80
+ right: 'left',
81
+ bottom: 'top',
82
+ left: 'right'
83
+ }[finalPlacement.split('-')[0]];
84
+ let arrowTransform = 'none';
85
+ switch (staticSide) {
86
+ case 'right':
87
+ arrowTransform = 'rotateY(180deg)';
88
+ break;
89
+ case 'left':
90
+ arrowTransform = 'none';
91
+ break;
92
+ case 'top':
93
+ arrowTransform = 'rotate(90deg)';
94
+ break;
95
+ case 'bottom':
96
+ arrowTransform = 'rotate(-90deg)';
97
+ break;
98
+ }
99
+ if (arrowRef.current) {
100
+ Object.assign(arrowRef.current.style, {
101
+ left: arrowX != null ? `${arrowX}px` : '',
102
+ top: arrowY != null ? `${arrowY}px` : '',
103
+ right: '',
104
+ bottom: '',
105
+ [staticSide]: '-6px',
106
+ transform: arrowTransform
107
+ });
108
+ }
109
+ });
110
+ const updatedChildren = /*#__PURE__*/cloneElement(children,
111
+ // eslint-disable-line @typescript-eslint/no-explicit-any
112
+ {
113
+ ...getReferenceProps(children.props),
114
+ ref: mergeRefs(
115
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
116
+ children.props.ref, mergedAnchorRef)
117
+ });
118
+ useEffect(() => {
119
+ if (!elements.floating) return;
120
+ if (elements.floating.isConnected && shouldOpen && open) {
121
+ elements.floating.showPopover();
122
+ }
123
+ }, [open, shouldOpen, elements.floating]);
124
+ const TooltipEl = /*#__PURE__*/jsxs(StyledTooltip, {
125
+ popover: "manual",
126
+ ...rest,
127
+ ...getFloatingProps({
128
+ ref: tooltipRef,
129
+ className: `eds-tooltip ${rest.className ?? ''}`,
130
+ style: {
131
+ ...style,
132
+ position: strategy,
133
+ top: y || 0,
134
+ left: x || 0
135
+ }
136
+ }),
137
+ children: [title, /*#__PURE__*/jsx(ArrowWrapper, {
138
+ ref: arrowRef,
139
+ children: /*#__PURE__*/jsx(TooltipArrow, {
140
+ className: "arrowSvg",
141
+ children: /*#__PURE__*/jsx("path", {
142
+ d: "M0.504838 4.86885C-0.168399 4.48524 -0.168399 3.51476 0.504838 3.13115L6 8.59227e-08L6 8L0.504838 4.86885Z"
143
+ })
144
+ })
145
+ })]
146
+ });
147
+ return /*#__PURE__*/jsxs(Fragment, {
148
+ children: [updatedChildren, shouldOpen && open && !disabled && /*#__PURE__*/createPortal(TooltipEl, portalContainer ?? rootElement ?? document.body)]
149
+ });
150
+ });
151
+
152
+ export { Tooltip };
@@ -0,0 +1,54 @@
1
+ import { tokens } from '@equinor/eds-tokens';
2
+
3
+ const {
4
+ colors: {
5
+ text: {
6
+ static_icons__primary_white: {
7
+ rgba: white
8
+ }
9
+ },
10
+ ui: {
11
+ background__overlay: {
12
+ rgba: background
13
+ }
14
+ }
15
+ },
16
+ typography: {
17
+ ui
18
+ },
19
+ spacings: {
20
+ comfortable: {
21
+ x_large: spacingXlarge,
22
+ small: spacingSmall
23
+ }
24
+ },
25
+ shape: {
26
+ corners: {
27
+ borderRadius
28
+ }
29
+ }
30
+ } = tokens;
31
+ const tooltip = {
32
+ typography: {
33
+ ...ui.tooltip,
34
+ color: white
35
+ },
36
+ background,
37
+ border: {
38
+ type: 'border',
39
+ radius: borderRadius
40
+ },
41
+ entities: {
42
+ arrow: {
43
+ width: '6px',
44
+ height: spacingSmall}
45
+ },
46
+ spacings: {
47
+ left: spacingSmall,
48
+ right: spacingSmall,
49
+ top: spacingSmall,
50
+ bottom: spacingSmall
51
+ }
52
+ };
53
+
54
+ export { tooltip };
@@ -0,0 +1,67 @@
1
+ import { forwardRef } from 'react';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ /**
5
+ * TypographyNext component for flexible typography with baseline grid support.
6
+ *
7
+ * Provides full control over typography properties including family, size,
8
+ * lineHeight, baseline alignment, weight, and tracking.
9
+ *
10
+ * **Display behavior:** Elements render as `display: block` by default for
11
+ * text-box trimming and baseline grid alignment. Override with CSS if needed.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * import { TypographyNext as Typography } from '@equinor/eds-core-react'
16
+ *
17
+ * <Typography
18
+ * family="ui"
19
+ * size="md"
20
+ * lineHeight="default"
21
+ * baseline="grid"
22
+ * weight="normal"
23
+ * tracking="normal"
24
+ * >
25
+ * Text content (renders as block-level by default)
26
+ * </Typography>
27
+ *
28
+ * <Typography
29
+ * as="h1"
30
+ * family="header"
31
+ * size="3xl"
32
+ * lineHeight="squished"
33
+ * baseline="grid"
34
+ * weight="bolder"
35
+ * tracking="tight"
36
+ * >
37
+ * Page heading
38
+ * </Typography>
39
+ * ```
40
+ */
41
+ const TypographyNext = /*#__PURE__*/forwardRef(({
42
+ as = 'span',
43
+ family,
44
+ size,
45
+ baseline,
46
+ lineHeight,
47
+ weight,
48
+ tracking,
49
+ debug,
50
+ ...rest
51
+ }, ref) => {
52
+ const Component = as;
53
+ return /*#__PURE__*/jsx(Component, {
54
+ ref: ref,
55
+ "data-font-family": family,
56
+ "data-font-size": size,
57
+ "data-baseline": baseline || undefined,
58
+ "data-line-height": lineHeight || undefined,
59
+ "data-font-weight": weight || undefined,
60
+ "data-tracking": tracking || undefined,
61
+ "data-debug": debug ? '' : undefined,
62
+ ...rest
63
+ });
64
+ });
65
+ TypographyNext.displayName = 'TypographyNext';
66
+
67
+ export { TypographyNext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/eds-core-react",
3
- "version": "2.3.1-beta.0",
3
+ "version": "2.3.2",
4
4
  "description": "The React implementation of the Equinor Design System",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -31,14 +31,7 @@
31
31
  "types": "./dist/types/index.d.ts",
32
32
  "import": "./dist/esm/index.js",
33
33
  "require": "./dist/eds-core-react.cjs"
34
- },
35
- "./next": {
36
- "types": "./dist/types/index.next.d.ts",
37
- "import": "./dist/esm/index.next.js",
38
- "require": "./dist/index.next.cjs"
39
- },
40
- "./next/index.css": "./build/index.css",
41
- "./next/index.min.css": "./build/index.min.css"
34
+ }
42
35
  },
43
36
  "keywords": [
44
37
  "eds",
@@ -104,9 +97,9 @@
104
97
  "@tanstack/react-virtual": "3.13.12",
105
98
  "downshift": "9.0.10",
106
99
  "react-aria": "^3.44.0",
107
- "@equinor/eds-utils": "^2.0.0",
100
+ "@equinor/eds-tokens": "^2.1.1",
108
101
  "@equinor/eds-icons": "^1.2.0",
109
- "@equinor/eds-tokens": "^2.1.1"
102
+ "@equinor/eds-utils": "^2.0.0"
110
103
  },
111
104
  "scripts": {
112
105
  "build": "rollup -c && tsc -p tsconfig.build.json",
File without changes