Skip to content

Commit

Permalink
chore: 📝 Rename trigger context (#2782)
Browse files Browse the repository at this point in the history
resolves #2453

---------

Co-authored-by: Michael Marszalek <[email protected]>
  • Loading branch information
Barsnes and mimarz authored Nov 15, 2024
1 parent f1424ff commit 436b876
Show file tree
Hide file tree
Showing 31 changed files with 187 additions and 176 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-buttons-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-react": patch
---

Dropdown: Rename `DropdownContext` to `DropdownTriggerContext`
5 changes: 5 additions & 0 deletions .changeset/fluffy-coins-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-react": patch
---

Modal: Rename `ModalContext` to `ModalTriggerContext`
5 changes: 5 additions & 0 deletions .changeset/violet-steaks-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-react": patch
---

Popover: Rename `PopoverContext` to `PopoverTriggerContext`
100 changes: 46 additions & 54 deletions apps/_components/src/ColorModal/ColorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,59 +52,52 @@ export const ColorModal = ({
weight,
}: ColorModalProps) => {
return (
<Modal.Context>
<Modal
ref={colorModalRef}
style={{
maxWidth: '1050px',
}}
backdropClose
>
<Modal.Block>
<Heading data-size='xs'>
{`${capitalizeFirstLetter(namespace)} ${capitalizeFirstLetter(getColorNameFromNumber(weight))}`}
</Heading>
</Modal.Block>
<Modal.Block className={classes.modalContent}>
<div className={classes.description}>
{getColorDescription({
weight,
namespace,
})}
</div>
<div className={classes.container}>
<div className={classes.left}>
<Field label='Hexkode:' value={hex} copyBtn />
<Field
label='HSLuv:'
value={
hexToHsluv(hex)[0].toFixed(0) +
'° ' +
hexToHsluv(hex)[1].toFixed(0) +
'% ' +
hexToHsluv(hex)[2].toFixed(0) +
'%'
}
/>
<Field
label='CSS variabel:'
value={getCssVariable(namespace, weight)}
copyBtn
/>
<Modal
ref={colorModalRef}
style={{
maxWidth: '1050px',
}}
backdropClose
>
<Modal.Block>
<Heading data-size='xs'>
{`${capitalizeFirstLetter(namespace)} ${capitalizeFirstLetter(getColorNameFromNumber(weight))}`}
</Heading>
</Modal.Block>
<Modal.Block className={classes.modalContent}>
<div className={classes.description}>
{getColorDescription({
weight,
namespace,
})}
</div>
<div className={classes.container}>
<div className={classes.left}>
<Field label='Hexkode:' value={hex} copyBtn />
<Field
label='HSLuv:'
value={
hexToHsluv(hex)[0].toFixed(0) +
'° ' +
hexToHsluv(hex)[1].toFixed(0) +
'% ' +
hexToHsluv(hex)[2].toFixed(0) +
'%'
}
/>
<Field
label='CSS variabel:'
value={getCssVariable(namespace, weight)}
copyBtn
/>

{weight !== 9 && weight !== 10 && weight !== 11 && (
<Field
label='Brukes mot:'
value={getColorCombinations(weight)}
/>
)}
</div>
<div
className={classes.right}
style={{ backgroundColor: hex }}
></div>
{weight !== 9 && weight !== 10 && weight !== 11 && (
<Field label='Brukes mot:' value={getColorCombinations(weight)} />
)}
</div>
{/* <Accordion.Root
<div className={classes.right} style={{ backgroundColor: hex }}></div>
</div>
{/* <Accordion.Root
color='neutral'
className={classes.accordion}
>
Expand All @@ -123,8 +116,7 @@ export const ColorModal = ({
</Accordion.Content>
</Accordion.Item>
</Accordion.Root> */}
</Modal.Block>
</Modal>
</Modal.Context>
</Modal.Block>
</Modal>
);
};
4 changes: 2 additions & 2 deletions apps/storefront/components/Tokens/TokenList/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const TokenList = ({
{(showThemePicker || showModeSwitcher) && (
<div className={classes.toggleGroup}>
{showModeSwitcher && (
<Dropdown.Context>
<Dropdown.TriggerContext>
<Dropdown.Trigger variant='secondary'>
Mode: {capitalizeString(mode)}
</Dropdown.Trigger>
Expand All @@ -238,7 +238,7 @@ const TokenList = ({
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
</Dropdown.Context>
</Dropdown.TriggerContext>
)}
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions apps/theme/components/Previews/Components/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export const Components = () => {
</Alert>
</div>
<div className={cl(classes.card, classes.dropdown)}>
<Dropdown.Context>
<Dropdown.TriggerContext>
<Dropdown.Trigger data-size='sm'>Velg språk</Dropdown.Trigger>
<Dropdown placement='top' data-size='sm'>
<Dropdown.Item>
Expand All @@ -413,7 +413,7 @@ export const Components = () => {
<HelpText aria-label='Du har ikke valgt språk'>
Velg språk for å endre innholdet på siden
</HelpText>
</Dropdown.Context>
</Dropdown.TriggerContext>
</div>
<div className={cl(classes.card, classes.loaders)}>
<div className={classes.loadersRest}>
Expand Down
4 changes: 2 additions & 2 deletions apps/theme/components/TokenModal/TokenModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const TokenModal = ({
};

return (
<Modal.Context>
<Modal.TriggerContext>
<Modal.Trigger
className={classes.trigger}
onClick={() => {
Expand Down Expand Up @@ -213,6 +213,6 @@ export const TokenModal = ({
</div>
</div>
</Modal>
</Modal.Context>
</Modal.TriggerContext>
);
};
4 changes: 2 additions & 2 deletions packages/react/src/components/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const WithImage: Story = () => (
);

export const InDropdown: Story = () => (
<Dropdown.Context>
<Dropdown.TriggerContext>
<Dropdown.Trigger variant='tertiary'>
<Avatar aria-label='Ola Nordmann' data-size='sm'>
ON
Expand Down Expand Up @@ -108,7 +108,7 @@ export const InDropdown: Story = () => (
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
</Dropdown.Context>
</Dropdown.TriggerContext>
);
InDropdown.parameters = {
layout: 'fullscreen',
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/Dropdown/Dropdown.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Dropdown } from './';
import { Dropdown } from '@digdir/designsystemet-react';

// med context
<Dropdown.Context>
<Dropdown.TriggerContext>
<Dropdown.Trigger>Trigger</Dropdown.Trigger>
<Dropdown>
<Dropdown.Heading>Heading</Dropdown.Heading>
Expand All @@ -28,7 +28,7 @@ import { Dropdown } from '@digdir/designsystemet-react';
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
</Dropdown.Context>
</Dropdown.TriggerContext>

// uten context
<Button popovertarget="my-dropdown">Trigger</Button>
Expand Down
12 changes: 6 additions & 6 deletions packages/react/src/components/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {

export const Preview: StoryFn<typeof Dropdown> = (args) => {
return (
<Dropdown.Context>
<Dropdown.TriggerContext>
<Dropdown.Trigger>Dropdown</Dropdown.Trigger>
<Dropdown {...args}>
<Dropdown.Heading>First heading</Dropdown.Heading>
Expand All @@ -57,7 +57,7 @@ export const Preview: StoryFn<typeof Dropdown> = (args) => {
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
</Dropdown.Context>
</Dropdown.TriggerContext>
);
};

Expand All @@ -68,7 +68,7 @@ Preview.args = {

export const Icons: StoryFn<typeof Dropdown> = (args) => {
return (
<Dropdown.Context>
<Dropdown.TriggerContext>
<Dropdown.Trigger>Dropdown</Dropdown.Trigger>
<Dropdown {...args}>
<Dropdown.List>
Expand Down Expand Up @@ -98,15 +98,15 @@ export const Icons: StoryFn<typeof Dropdown> = (args) => {
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
</Dropdown.Context>
</Dropdown.TriggerContext>
);
};

export const Controlled: StoryFn<typeof Dropdown> = () => {
const [open, setOpen] = useState(false);

return (
<Dropdown.Context>
<Dropdown.TriggerContext>
<Dropdown.Trigger onClick={() => setOpen(!open)}>
Dropdown
{open ? <ChevronDownIcon aria-hidden /> : <ChevronUpIcon aria-hidden />}
Expand Down Expand Up @@ -139,7 +139,7 @@ export const Controlled: StoryFn<typeof Dropdown> = () => {
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
</Dropdown.Context>
</Dropdown.TriggerContext>
);
};

Expand Down
10 changes: 5 additions & 5 deletions packages/react/src/components/Dropdown/Dropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { render as renderRtl, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { act } from 'react';

import type { DropdownContextProps } from './DropdownContext';
import type { DropdownTriggerContextProps } from './DropdownTriggerContext';

import { Dropdown } from '.';

const Comp = (args: Partial<DropdownContextProps>) => {
const Comp = (args: Partial<DropdownTriggerContextProps>) => {
return (
<Dropdown.Context {...args}>
<Dropdown.TriggerContext {...args}>
<Dropdown.Trigger>Dropdown</Dropdown.Trigger>
<Dropdown>
<Dropdown.Heading>Links</Dropdown.Heading>
Expand All @@ -19,11 +19,11 @@ const Comp = (args: Partial<DropdownContextProps>) => {
{args.children}
</Dropdown.List>
</Dropdown>
</Dropdown.Context>
</Dropdown.TriggerContext>
);
};

const render = async (props: Partial<DropdownContextProps> = {}) => {
const render = async (props: Partial<DropdownTriggerContextProps> = {}) => {
/* Flush microtasks */
await act(async () => {});
const user = userEvent.setup();
Expand Down
26 changes: 0 additions & 26 deletions packages/react/src/components/Dropdown/DropdownContext.tsx

This file was deleted.

28 changes: 28 additions & 0 deletions packages/react/src/components/Dropdown/DropdownTriggerContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { ReactNode } from 'react';

import { PopoverTriggerContext } from '../Popover';

export type DropdownTriggerContextProps = {
children: ReactNode;
};

/**
* DropdownTriggerContext enables use of the `.Trigger` for the Dropdown component.
* @example
* <Dropdown.TriggerContext>
* <Dropdown.Trigger>Dropdown</Dropdown.Trigger>
* <Dropdown>
* <Dropdown.Heading>Heading</Dropdown.Heading>
* <Dropdown.List>
* <Dropdown.Item>Button 1</Dropdown.Item>
* </Dropdown.List>
* </Dropdown>
* </Dropdown.TriggerContext>
*/
export const DropdownTriggerContext = ({
children,
}: DropdownTriggerContextProps) => {
return <PopoverTriggerContext>{children}</PopoverTriggerContext>;
};

DropdownTriggerContext.displayName = 'DropdownTriggerContext';
Loading

0 comments on commit 436b876

Please sign in to comment.