Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#255 Move @mediamonks/transition-presence components into this repository #256

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plop-templates/hook/{{camelCase hookName}}.mdx.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title='hooks/{{camelCase hookName}}' />
<Meta title='Hooks / {{camelCase hookName}}' />

# {{camelCase hookName}}

Expand Down
12 changes: 7 additions & 5 deletions plop-templates/hook/{{camelCase hookName}}.stories.tsx.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { StoryObj } from '@storybook/react';
import type { Meta, StoryObj } from '@storybook/react';
import type { ReactElement } from 'react';
import { {{camelCase hookName}} } from './{{camelCase hookName}}.js';

export default {
title: 'hooks/{{camelCase hookName}}',
};
const meta = {
title: 'Hooks / {{camelCase hookName}}',
} satisfies Meta;

type Story = StoryObj<typeof meta>;

function DemoComponent(): ReactElement {
{{camelCase hookName}}();
Expand All @@ -28,7 +30,7 @@ function DemoComponent(): ReactElement {
);
}

export const Demo: StoryObj = {
export const Demo: Story = {
render() {
return <DemoComponent />;
}
Expand Down
28 changes: 28 additions & 0 deletions src/_utils/childrenAreEqual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { type ReactElement, type ReactFragment } from 'react';

export function childrenAreEqual(
previousChildren: ReactElement | ReactFragment | null,
nextChildren: ReactElement | ReactFragment | null,
): boolean {
if (previousChildren === nextChildren) {
return true;
}

// React reconciler will create a new instance when children type changes
if (
(previousChildren !== null && 'type' in previousChildren && previousChildren.type) !==
(nextChildren !== null && 'type' in nextChildren && nextChildren.type)
) {
return false;
}

// React reconciler will create a new instance when children key changes
if (
(previousChildren !== null && 'key' in previousChildren && previousChildren.key) !==
(nextChildren !== null && 'key' in nextChildren && nextChildren.key)
) {
return false;
}

return true;
}
5 changes: 5 additions & 0 deletions src/_utils/getId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let id = 0;

export function getId(): string {
return (id++ % Number.MAX_SAFE_INTEGER).toString();
}
2 changes: 1 addition & 1 deletion src/components/AutoFill/AutoFill.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Canvas, Meta } from '@storybook/blocks';
import * as stories from './AutoFill.stories';

<Meta title="components/AutoFill" />
<Meta title="Components / AutoFill" />

# AutoFill

Expand Down
17 changes: 8 additions & 9 deletions src/components/AutoFill/AutoFill.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/* eslint-disable react/jsx-no-literals, react/no-multi-comp */
/* eslint-disable react/jsx-no-literals */
import { type Meta, type StoryObj } from '@storybook/react';
import type { ReactElement } from 'react';
import { AutoFill } from './AutoFill.js';

const meta = {
title: 'components/AutoFill',
title: 'Components / AutoFill',
component: AutoFill,
} satisfies Meta;

type Story = StoryObj<typeof meta>;

export default meta;

export const Horizontal = {
render(): ReactElement {
export const Horizontal: Story = {
render() {
return (
<div
style={{
Expand Down Expand Up @@ -59,10 +58,10 @@ export const Horizontal = {
args: {
children: <div />,
},
} satisfies Story;
};

export const Vertical = {
render(): ReactElement {
export const Vertical: Story = {
render() {
return (
<div
style={{
Expand Down Expand Up @@ -95,4 +94,4 @@ export const Vertical = {
args: {
children: <div />,
},
} satisfies Story;
};
2 changes: 1 addition & 1 deletion src/hocs/ensuredForwardRef/ensuredForwardRef.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title="Higher-Order Components/ensuredForwardRef" />
<Meta title="Higher-Order components / ensuredForwardRef" />

# ensuredForwardRef

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useClientSideValue/useClientSideValue.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title="hooks/useClientSideValue" />
<Meta title="Hooks / useClientSideValue" />

# useClientSideValue

Expand Down
16 changes: 10 additions & 6 deletions src/hooks/useClientSideValue/useClientSideValue.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* eslint-disable react-hooks/rules-of-hooks */
/* eslint-disable react/jsx-no-literals */
import type { StoryObj } from '@storybook/react';
import type { Meta, StoryObj } from '@storybook/react';
import { useClientSideValue } from './useClientSideValue.js';

export default {
title: 'hooks/useClientSideValue',
};
const meta = {
title: 'Hooks / useClientSideValue',
} satisfies Meta;

export default meta;

type Story = StoryObj<typeof meta>;

const note = (
<div className="alert alert-secondary">
Expand All @@ -17,7 +21,7 @@ const note = (
</div>
);

export const Demo: StoryObj = {
export const Demo: Story = {
render() {
const value = useClientSideValue(Date.now, 0);

Expand All @@ -33,7 +37,7 @@ export const Demo: StoryObj = {
},
};

export const Nullable: StoryObj = {
export const Nullable: Story = {
render() {
const value = useClientSideValue<number | null>(Date.now, null);

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useClientSideValue/useClientSideValue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import { useMount } from '../useMount/useMount.js';
import { useMount } from '../../lifecycle/hooks/useMount/useMount.js';

/**
* Hook that returns the value returned by a callback function that is only called on client-side.
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useEventListener/useEventListener.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title="hooks/useEventListener" />
<Meta title="Hooks / useEventListener" />

# useEventListener

Expand Down
14 changes: 9 additions & 5 deletions src/hooks/useEventListener/useEventListener.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* eslint-disable react/jsx-no-literals */
import type { StoryObj } from '@storybook/react';
import type { Meta, StoryObj } from '@storybook/react';
import { useState, type ReactElement } from 'react';
import { useEventListener } from './useEventListener.js';

export default {
title: 'hooks/useEventListener',
};
const meta = {
title: 'Hooks / useEventListener',
} satisfies Meta;

export default meta;

type Story = StoryObj<typeof meta>;

function DemoComponent(): ReactElement {
const [text, setText] = useState<ReadonlyArray<string>>([]);
Expand Down Expand Up @@ -40,7 +44,7 @@ function DemoComponent(): ReactElement {
);
}

export const Demo: StoryObj = {
export const Demo: Story = {
render() {
return <DemoComponent />;
},
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useForceRerender/useForceRerender.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title="hooks/lifecycle/useForceRerender" />
<Meta title="Hooks / useForceRerender" />

# useForceRerender

Expand Down
14 changes: 9 additions & 5 deletions src/hooks/useForceRerender/useForceRerender.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* eslint-disable react/jsx-no-literals,react/jsx-handler-names */
import type { StoryObj } from '@storybook/react';
import type { Meta, StoryObj } from '@storybook/react';
import { useForceRerender } from './useForceRerender.js';

export default {
title: 'hooks/lifecycle/useForceRerender',
};
const meta = {
title: 'Hooks / useForceRerender',
} satisfies Meta;

export default meta;

type Story = StoryObj<typeof meta>;

function DemoComponent(): JSX.Element {
const forceRerender = useForceRerender();
Expand All @@ -28,7 +32,7 @@ function DemoComponent(): JSX.Element {
);
}

export const Demo: StoryObj = {
export const Demo: Story = {
render() {
return <DemoComponent />;
},
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useHasFocus/useHasFocus.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title="hooks/useHasFocus" />
<Meta title="Hooks / useHasFocus" />

# useHasFocus

Expand Down
14 changes: 9 additions & 5 deletions src/hooks/useHasFocus/useHasFocus.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* eslint-disable react/jsx-no-literals */
import type { StoryObj } from '@storybook/react';
import type { Meta, StoryObj } from '@storybook/react';
import { useEffect, useRef, useState, type ReactElement } from 'react';
import { useHasFocus } from './useHasFocus.js';

export default {
title: 'hooks/useHasFocus',
};
const meta = {
title: 'Hooks / useHasFocus',
} satisfies Meta;

export default meta;

type Story = StoryObj<typeof meta>;

function DemoComponent(): ReactElement {
const ref = useRef<HTMLButtonElement>(null);
Expand Down Expand Up @@ -37,7 +41,7 @@ function DemoComponent(): ReactElement {
);
}

export const Demo: StoryObj = {
export const Demo: Story = {
render() {
return <DemoComponent />;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, Canvas } from '@storybook/blocks';
import * as stories from './useIntersectionObserver.stories';

<Meta title="hooks/useIntersectionObserver" />
<Meta title="Hooks / useIntersectionObserver" />

# useIntersectionObserver

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { arrayRef } from '../../index.js';
import { useIntersectionObserver } from './useIntersectionObserver.js';

const meta = {
title: 'hooks/useIntersectionObserver',
title: 'Hooks / useIntersectionObserver',
} satisfies Meta;

export default meta;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useInterval/useInterval.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title="hooks/useInterval" />
<Meta title="Hooks / useInterval" />

# `useInterval`

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useInterval/useInterval.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRef, useState, type ReactElement } from 'react';
import { useInterval } from './useInterval.js';

const meta = {
title: 'hooks/useInterval',
title: 'Hooks / useInterval',
} satisfies Meta;

type Story = StoryObj<typeof meta>;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useMediaDuration/useMediaDuration.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title="hooks/useMediaDuration" />
<Meta title="Hooks / useMediaDuration" />

# useMediaDuration

Expand Down
14 changes: 9 additions & 5 deletions src/hooks/useMediaDuration/useMediaDuration.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/* eslint-disable react/jsx-no-literals */
import type { StoryObj } from '@storybook/react';
import type { Meta, StoryObj } from '@storybook/react';
import type { ReactElement } from 'react';
import { useRefs } from '../useRefs/useRefs.js';
import type { MutableRefs } from '../useRefs/useRefs.types.js';
import { useMediaDuration } from './useMediaDuration.js';

export default {
title: 'hooks/useMediaDuration',
};
const meta = {
title: 'Hooks / useMediaDuration',
} satisfies Meta;

export default meta;

type Story = StoryObj<typeof meta>;

export type DemoComponentRefs = MutableRefs<{
video: HTMLVideoElement;
Expand Down Expand Up @@ -54,7 +58,7 @@ function DemoComponent(): ReactElement {
);
}

export const Demo: StoryObj = {
export const Demo: Story = {
render() {
return <DemoComponent />;
},
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useMediaQuery/useMediaQuery.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title="hooks/useMediaQuery" />
<Meta title="Hooks / useMediaQuery" />

# useMediaQuery

Expand Down
Loading
Loading