Skip to content

Commit

Permalink
feat: Add basic SSR support and peerDependecies to react 18.2.0 (#864)
Browse files Browse the repository at this point in the history
Co-authored-by: Marianne Røsvik <[email protected]>
Co-authored-by: Michael Marszalek <[email protected]>
Co-authored-by: Tomas Engebretsen <[email protected]>
Co-authored-by: Magnus Revheim Martinsen <[email protected]>
Co-authored-by: Michael Marszalek <[email protected]>
  • Loading branch information
6 people authored Sep 29, 2023
1 parent d94a16c commit d512ee2
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 66 deletions.
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"clean": "rimraf dist"
},
"peerDependencies": {
"react": ">=16.8",
"react-dom": ">=16.8"
"react": ">=18.2.0",
"react-dom": ">=18.2.0"
},
"publishConfig": {
"access": "public"
Expand Down
42 changes: 21 additions & 21 deletions packages/react/rollup-terser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ simpler plugin that invokes Terser without Jest workers.
import { minify } from 'terser';

function terser(terserOptions = {}) {
return {
name: 'terser',
return {
name: 'terser',

async renderChunk(code, _chunk, outputOptions) {
const defaultOptions = {
sourceMap: !!outputOptions.sourcemap,
};
async renderChunk(code, _chunk, outputOptions) {
const defaultOptions = {
sourceMap: !!outputOptions.sourcemap,
};

// eslint-disable-next-line default-case
switch (outputOptions.format) {
case 'es':
case 'esm':
defaultOptions.module = true;
break;
case 'cjs':
defaultOptions.toplevel = true;
break;
}
// eslint-disable-next-line default-case
switch (outputOptions.format) {
case 'es':
case 'esm':
defaultOptions.module = true;
break;
case 'cjs':
defaultOptions.toplevel = true;
break;
}

const effectiveTerserOptions = { ...defaultOptions, ...terserOptions };
return await minify(code, effectiveTerserOptions);
},
};
const effectiveTerserOptions = { ...defaultOptions, ...terserOptions };
return await minify(code, effectiveTerserOptions);
},
};
}

export default terser;
export default terser;
10 changes: 9 additions & 1 deletion packages/react/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ export default [
{
file: packageJson.main,
format: 'cjs',
banner: "'use client';",
},
{
file: packageJson.module,
format: 'esm',
banner: "'use client';",
},
],
external: [
Expand All @@ -44,13 +46,19 @@ export default [
typescript({ tsconfig: './tsconfig.build.json' }),
svgr({ exportType: 'named' }),
postcss(),
terser(),
terser({
compress: {
// Needed until https://github.com/terser/terser/issues/1320 is fixed
directives: false,
},
}),
image(),
],
},
{
input: 'dist/types/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'esm' }],

plugins: [dts()],
external: [/@altinn\/figma-design-tokens/, /\.css$/],
},
Expand Down
33 changes: 17 additions & 16 deletions packages/react/src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ export type AccordionProps = {
children: React.ReactNode;
} & HTMLAttributes<HTMLDivElement>;

export const Accordion = forwardRef<HTMLDivElement, AccordionProps>(
({ border = false, color = 'neutral', className, ...rest }, ref) => (
<div
{...rest}
className={cn(
classes.accordion,
classes[color],
{
[classes.border]: border,
},
className,
)}
ref={ref}
/>
),
);
export const Accordion = forwardRef<
HTMLDivElement,
AccordionProps & { children: React.ReactNode }
>(({ border = false, color = 'neutral', className, ...rest }, ref) => (
<div
{...rest}
className={cn(
classes.accordion,
classes[color],
{
[classes.border]: border,
},
className,
)}
ref={ref}
/>
));
2 changes: 1 addition & 1 deletion packages/react/src/components/Accordion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export type {
AccordionHeaderProps,
AccordionItemProps,
};
export { Accordion };
export { Accordion, AccordionItem, AccordionContent, AccordionHeader };
20 changes: 10 additions & 10 deletions packages/react/src/components/Chip/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Group } from './Group';
import { Group as ChipGroup } from './Group';
import type { ChipGroupProps } from './Group';
import { RemovableChip } from './Removable';
import { RemovableChip as ChipRemovable } from './Removable';
import type { RemovableChipProps } from './Removable';
import { ToggleChip } from './Toggle';
import { ToggleChip as ChipToggle } from './Toggle';
import type { ToggleChipProps } from './Toggle/';

type ChipComponent = {
Expand All @@ -14,20 +14,20 @@ type ChipComponent = {
* <Chip.Removable>Tekst</Chip.Removable>
* </Chip.Group>
*/
Group: typeof Group;
Removable: typeof RemovableChip;
Toggle: typeof ToggleChip;
Group: typeof ChipGroup;
Removable: typeof ChipRemovable;
Toggle: typeof ChipToggle;
};

const Chip: ChipComponent = {
Group: Group,
Removable: RemovableChip,
Toggle: ToggleChip,
Group: ChipGroup,
Removable: ChipRemovable,
Toggle: ChipToggle,
};

Chip.Group.displayName = 'Chip.Group';
Chip.Removable.displayName = 'Chip.Removable';
Chip.Toggle.displayName = 'Chip.Toggle';

export type { RemovableChipProps, ToggleChipProps, ChipGroupProps };
export { Chip };
export { Chip, ChipGroup, ChipRemovable, ChipToggle };
2 changes: 1 addition & 1 deletion packages/react/src/components/ToggleGroup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ ToggleGroup.Item = ToggleGroupItem;

ToggleGroup.Item.displayName = 'ToggleGroup.Item';

export { ToggleGroup };
export { ToggleGroup, ToggleGroupItem };
2 changes: 1 addition & 1 deletion packages/react/src/components/form/Checkbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Checkbox.Group.displayName = 'Checkbox.Group';

export type { CheckboxProps, CheckboxGroupProps };

export { Checkbox };
export { Checkbox, CheckboxGroup };
2 changes: 1 addition & 1 deletion packages/react/src/components/form/Radio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Radio.Group.displayName = 'Radio.Group';

export type { RadioProps, RadioGroupProps };

export { Radio };
export { Radio, RadioGroup };
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Brønnøysundregistrene har med hjelp fra Blindeforbundet, undersøkt hvordan me
<ResponsiveIframe
src='https://player.vimeo.com/video/713674977?h=31aae91dc0'
title='Video from Brregs vimeo accounting showing people with reduced vision use digital products'
frameborder='0'
frameBorder='0'
allow='autoplay; fullscreen; picture-in-picture'
allowfullscreen
allowFullScreen
aspectRatio='16-9'
></ResponsiveIframe>
16 changes: 8 additions & 8 deletions storefront/pages/grunnleggende/for-designere/kom-i-gang.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Alle komponenter kommer med ulike varianter og egenskaper. I Button-komponenten
<ResponsiveIframe
src='/img/button-variant-properties.mp4'
title='Skjermopptak av Figma som viser hvordan bytte mellom ulike varianter av en knapp.'
frameborder='0'
frameBorder='0'
allow='autoplay; fullscreen; picture-in-picture'
allowfullscreen
allowFullScreen
aspectRatio='16-9'
></ResponsiveIframe>

Expand All @@ -65,9 +65,9 @@ Alle tokens er i sync med [Figma variabler](https://docs.tokens.studio/variables
<ResponsiveIframe
src='/img/brand-variables.mp4'
title='Skjermopptak av Figma som viser hvordan man kan bytte mellom ulike brands i Figma'
frameborder='0'
frameBorder='0'
allow='autoplay; fullscreen; picture-in-picture'
allowfullscreen
allowFullScreen
aspectRatio='16-9'
></ResponsiveIframe>

Expand All @@ -78,9 +78,9 @@ For admingrensesnitt eller ekspertverktøy kan compact-mode benyttes. Tekststør
<ResponsiveIframe
src='/img/density2.mp4'
title='Skjermopptak av Figma som viser hvordan man kan bytte mellom normal og kompakt i Figma'
frameborder='0'
frameBorder='0'
allow='autoplay; fullscreen; picture-in-picture'
allowfullscreen
allowFullScreen
aspectRatio='16-9'
></ResponsiveIframe>

Expand All @@ -93,9 +93,9 @@ Les mer om [typografi](/grunnleggende/designelementer/typografi).
<ResponsiveIframe
src='/img/fluid-text-size.mp4'
title='Skjermopptak av Figma som viser hvordan størrelse og avstand på tekst blir mindre i en mindre viewport'
frameborder='0'
frameBorder='0'
allow='autoplay; fullscreen; picture-in-picture'
allowfullscreen
allowFullScreen
aspectRatio='16-9'
></ResponsiveIframe>

Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3925,8 +3925,8 @@ __metadata:
"@navikt/aksel-icons": ^3.2.4
react-number-format: 5.2.2
peerDependencies:
react: ">=16.8"
react-dom: ">=16.8"
react: ">=18.2.0"
react-dom: ">=18.2.0"
languageName: unknown
linkType: soft

Expand Down

0 comments on commit d512ee2

Please sign in to comment.