@ndlib/component-library 0.0.129 → 1.0.1

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.
@@ -73,7 +73,7 @@ const defaultFloatImageStyles = {
73
73
  float: 'right',
74
74
  margin: '16px',
75
75
  marginTop: '0px',
76
- width: '400px',
76
+ maxWidth: '400px',
77
77
  };
78
78
  const dynamicTopMarginStyles = {
79
79
  [firstChildAltSelector]: {
@@ -3,6 +3,8 @@ type MediaContextType = {
3
3
  screenSize: number;
4
4
  breakpoint: number;
5
5
  };
6
- export declare const MediaSizeProvider: React.FC<PropsWithChildren>;
6
+ export declare const MediaSizeProvider: React.FC<PropsWithChildren<{
7
+ useHydrationPatch?: boolean;
8
+ }>>;
7
9
  export declare const useMediaQuery: () => MediaContextType;
8
10
  export {};
@@ -1,28 +1,32 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext, useEffect, useMemo, useState, } from 'react';
2
+ import { createContext, useContext, useEffect, useState, } from 'react';
3
3
  import { useTheme } from '../../theme';
4
4
  const MediaContext = createContext({
5
5
  screenSize: -1,
6
6
  breakpoint: -1,
7
7
  });
8
- export const MediaSizeProvider = ({ children, }) => {
8
+ export const MediaSizeProvider = ({ useHydrationPatch, children }) => {
9
9
  const [renderCount, setRenderCount] = useState(0);
10
10
  const theme = useTheme();
11
11
  const breakpoints = theme.breakpoints.map((bp) => parseInt(bp.slice(0, -2)), [theme]);
12
- const { screenSize, breakpoint } = useMemo(() => {
12
+ const getBreakpoint = (screenSize) => {
13
+ const closestBreakpoint = breakpoints.findIndex((bp) => screenSize < bp);
14
+ return closestBreakpoint === -1 ? breakpoints.length : closestBreakpoint;
15
+ };
16
+ const initialScreenSize = useHydrationPatch || typeof window === 'undefined' ? -1 : window.innerWidth;
17
+ const initialBreakpoint = useHydrationPatch || typeof window === 'undefined'
18
+ ? -1
19
+ : getBreakpoint(window.innerWidth);
20
+ const [screenSize, setScreenSize] = useState(initialScreenSize);
21
+ const [breakpoint, setBreakpoint] = useState(initialBreakpoint);
22
+ useEffect(() => {
13
23
  if (typeof window === 'undefined') {
14
- return {
15
- screenSize: -1,
16
- breakpoint: -1,
17
- };
24
+ return;
18
25
  }
19
26
  const screenSize = window.innerWidth;
20
- const closestBreakpoint = breakpoints.findIndex((bp) => screenSize < bp);
21
- const breakpoint = closestBreakpoint === -1 ? breakpoints.length : closestBreakpoint;
22
- return {
23
- screenSize,
24
- breakpoint,
25
- };
27
+ const breakpoint = getBreakpoint(screenSize);
28
+ setScreenSize(screenSize);
29
+ setBreakpoint(breakpoint);
26
30
  }, [renderCount, breakpoints]);
27
31
  useEffect(() => {
28
32
  if (typeof window === 'undefined')
@@ -12,6 +12,7 @@ export type UiConfig = {
12
12
  loadFonts?: boolean;
13
13
  loadGlobalStyles?: boolean;
14
14
  includeTheme?: boolean;
15
+ useHydrationPatch?: boolean;
15
16
  };
16
17
  type UiProviderProps = PropsWithChildren<UiConfig>;
17
18
  export declare const UiProvider: React.FC<UiProviderProps>;
@@ -10,7 +10,7 @@ import { MediaSizeProvider } from './media';
10
10
  import StructuredData from '../composites/StructuredData';
11
11
  import { SnackBarProvider } from './snackBar';
12
12
  import { UniqueIdProvider } from './uniqueIds';
13
- export const UiProvider = ({ structuredData, env, components, alertsConfig, children, includeTheme = true, loadFonts, loadGlobalStyles, }) => {
14
- const core = (_jsxs(EnvironmentProvider, Object.assign({ env: env }, { children: [_jsx(MediaSizeProvider, { children: _jsx(ComponentConfigProvider, Object.assign({ config: components || {} }, { children: _jsx(UniqueIdProvider, { children: _jsx(SnackBarProvider, { children: _jsx(DialogsProvider, { children: _jsx(AlertsProvider, Object.assign({}, alertsConfig, { children: children })) }) }) }) })) }), loadGlobalStyles && _jsx(GlobalStyles, {}), loadFonts && _jsx(FontLoader, {}), structuredData && _jsx(StructuredData, Object.assign({}, structuredData))] })));
13
+ export const UiProvider = ({ structuredData, env, components, alertsConfig, children, includeTheme = true, loadFonts, loadGlobalStyles, useHydrationPatch = true, }) => {
14
+ const core = (_jsxs(EnvironmentProvider, Object.assign({ env: env }, { children: [_jsx(MediaSizeProvider, Object.assign({ useHydrationPatch: useHydrationPatch }, { children: _jsx(ComponentConfigProvider, Object.assign({ config: components || {} }, { children: _jsx(UniqueIdProvider, { children: _jsx(SnackBarProvider, { children: _jsx(DialogsProvider, { children: _jsx(AlertsProvider, Object.assign({}, alertsConfig, { children: children })) }) }) }) })) })), loadGlobalStyles && _jsx(GlobalStyles, {}), loadFonts && _jsx(FontLoader, {}), structuredData && _jsx(StructuredData, Object.assign({}, structuredData))] })));
15
15
  return includeTheme ? _jsx(ThemeProvider, { children: core }) : core;
16
16
  };
@@ -37,8 +37,6 @@ const globalStyles = css `
37
37
  small,
38
38
  strike,
39
39
  strong,
40
- sub,
41
- sup,
42
40
  tt,
43
41
  var,
44
42
  b,
@@ -91,6 +89,16 @@ const globalStyles = css `
91
89
  vertical-align: baseline;
92
90
  }
93
91
 
92
+ sub {
93
+ vertical-align: sub;
94
+ font-size: smaller;
95
+ }
96
+
97
+ sup {
98
+ vertical-align: super;
99
+ font-size: smaller;
100
+ }
101
+
94
102
  /* HTML5 display-role reset for older browsers */
95
103
  article,
96
104
  aside,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/component-library",
3
- "version": "0.0.129",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [