Skip to content

Commit

Permalink
add animate
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Bertrand committed Aug 14, 2023
1 parent 803e1b0 commit 0968771
Show file tree
Hide file tree
Showing 37 changed files with 2,199 additions and 505 deletions.
19 changes: 10 additions & 9 deletions apps/docs/components/CodeDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,16 @@ export const CodeDemo = ({
</>
)}
{code.length > 0 && (
<Button
color="violet"
variant="filled"
onPress={() => setShow((e) => !e)}
className="absolute bottom-0 right-0"
size="xs"
>
<Button.Text>{show ? 'Hide' : 'Show'}</Button.Text>
</Button>
<Box className="absolute bottom-0 right-0">
<Button
color="violet"
variant="filled"
onPress={() => setShow((e) => !e)}
size="xs"
>
<Button.Text>{show ? 'Hide' : 'Show'}</Button.Text>
</Button>
</Box>
)}
</YBox>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/components/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const Tabs = withStaticProperties(
const time = setTimeout(() => {
const [anchor] = asPath.match(/#(.*)$/g) || [];
if (anchor) {
let target = document.querySelector(`${anchor}`);
const target = document.querySelector(`${anchor}`);

if (!target) return;

Expand All @@ -32,7 +32,7 @@ export const Tabs = withStaticProperties(
}, 200);
return () => clearTimeout(time);
}
}, [isReady]);
}, [isReady, asPath]);

return (
<TabsNext
Expand Down
26 changes: 23 additions & 3 deletions apps/docs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/** @type {import('next').NextConfig} */

const withNextra = require('nextra')({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.tsx',
});
const path = require('path');

const { withMergeui } = require('@mergeui/next-adapter');

/** @type {import('next').NextConfig} */
module.exports = withNextra(
withMergeui({
images: {
Expand All @@ -16,5 +15,26 @@ module.exports = withNextra(
assetPrefix: process.env.NODE_ENV === 'development' ? '/' : '/mergeui/',
output: 'export',
transpilePackages: ['@mergeui/core'],
webpack: (config, { isServer, dev, webpack } = {}) => {
if (!config.plugins) {
config.plugins = [];
}
config.plugins.push(
new webpack.DefinePlugin({
__DEV__: dev,
})
);
// if (isServer) {
// config.plugins.push(
// new webpack.ProvidePlugin({
// requestAnimationFrame: path.resolve(
// __dirname,
// './node_modules/raf/polyfill.js'
// ),
// })
// );
// }
return config;
},
})
);
2 changes: 2 additions & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"nextra": "latest",
"nextra-theme-docs": "latest",
"postcss": "^8.4.27",
"raf": "^3.4.1",
"react": "^18.2.0",
"react-code-blocks": "^0.1.3",
"react-dom": "^18.2.0",
Expand All @@ -36,6 +37,7 @@
},
"devDependencies": {
"@types/node": "18.11.10",
"babel-preset-react-native": "^4.0.1",
"typescript": "^5.1.6"
}
}
3 changes: 3 additions & 0 deletions apps/docs/pages/ui/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"layout": {
"title": "Layout"
},
"animations": {
"title": "Animations"
},
"typography": {
"title": "Typography"
},
Expand Down
26 changes: 26 additions & 0 deletions apps/docs/pages/ui/animations/animate.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AnimateDemo } from '@mergeui/demo';
import { CodeDemo } from 'components/CodeDemo';
import { getStaticDemo } from 'components/getStaticDemo';
import { Tabs } from 'components/Tabs';
import { Table } from 'components/Table';

export const getStaticProps = getStaticDemo('ui/animations/Animate');

# Animate

Use moti js

<Tabs items={['Demo', 'Anatomy', 'Props']}>
<Tabs.Tab>
<CodeDemo Demo={AnimateDemo} />
</Tabs.Tab>
<Tabs.Tab>
```tsx
<Animate />
```
</Tabs.Tab>
<Tabs.Tab>
## Animate
<Table props={[]} />
</Tabs.Tab>
</Tabs>
44 changes: 7 additions & 37 deletions apps/docs/pages/ui/forms/switch.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { CodeDemo } from 'components/CodeDemo';
import { Tabs } from 'components/Tabs';
import { Table, Tr, Td, Th } from 'nextra/components';
import { getStaticDemo } from 'components/getStaticDemo';
import { SwitchDemo } from '@mergeui/demo';
import { Table } from 'components/Table';

export const getStaticProps = getStaticDemo("ui/forms/Switch")

# Switch

<Tabs items={["Demo", "Anatomy", "Props"]}>
<Tabs.Tab>
<CodeDemo />
<CodeDemo Demo={SwitchDemo} />
</Tabs.Tab>
<Tabs.Tab>
## Simple
Expand All @@ -26,41 +30,7 @@ import { Table, Tr, Td, Th } from 'nextra/components';
<Tabs.Tab>

## Button
<Table className="table-auto overflow-hidden w-full">
<Tr>
<Th>Props</Th>
<Th>default</Th>
<Th>Description</Th>
</Tr>
<Tr>
<Td>disabled</Td>
<Th>false</Th>
<Th>Description</Th>
</Tr>
<Tr>
<Td>loading</Td>
<Th>false</Th>
<Th>dsfsd dsfds dsfdsd dsfsd dsfds dsfdsd dsfsd dsfds dsfdsd dsfsd dsfds dsfdsd dsfsd dsfds dsfdsd</Th>
</Tr>
</Table>

## Button.Text
<Table props={[]} />

<Table className="table-auto overflow-hidden w-full">
<Tr>
<Th>Props</Th>
<Th>default</Th>
<Th>Description</Th>
</Tr>
</Table>
## Button.Icon
<Table className="table-auto overflow-hidden w-full">
<Tr>
<Th>Props</Th>
<Th>default</Th>
<Th>Description</Th>
</Tr>
</Table>

</Tabs.Tab>
</Tabs>
21 changes: 7 additions & 14 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,24 @@
"@types/react-native": "^0.72.2",
"babel-plugin-transform-remove-console": "^6.9.4",
"jest": "^29.5.0",
"moti": "^0.26.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-native": "^0.72.3",
"react-native-web": "^0.19.7",
"react-native-reanimated": "^3.4.2",
"tsconfig": "*"
},
"dependencies": {
"@mergeui/class-variance-authority": "*",
"inline-style-prefixer": "^6.0.1",
"normalize-css-color": "^1.0.2",
"twrnc": "^3.6.3"
},
"react-native-builder-bob": {
"source": "src",
"output": "lib",
"targets": [
"commonjs",
[
"module"
],
"typescript"
]
},
"files": [
"lib/",
"src/"
]
],
"peerDependencies": {
"moti": "^0.26.0",
"react-native-reanimated": "^3.4.2"
}
}
4 changes: 2 additions & 2 deletions packages/core/src/composeEventHandlers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ type Events = Object;
export type EventHandler<E extends Events> = (event: E) => void;

export function composeEventHandlers<E extends Events>(
og?: EventHandler<E> | null,
next?: EventHandler<E> | null,
og?: EventHandler<E> | null | false,
next?: EventHandler<E> | null | false,
{ checkDefaultPrevented = true } = {}
) {
if (!og || !next) {
Expand Down
142 changes: 142 additions & 0 deletions packages/core/src/extractPropertyState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import type {
Base,
BaseWithState,
ConfigSchema,
ConfigSchemaTheme,
Props,
State,
StateName,
} from './types';

export const extractState = <P, T extends ConfigSchema<P>>(
themeConfigProps: ConfigSchemaTheme<P, T>,
variantProps: Props<T>,
keyProperty: keyof Pick<Base<P>, 'animate' | 'className'>,
{
activeTheme,
hoverTheme,
focusTheme,
disabledTheme,
}: {
activeTheme?: Base<P>;
hoverTheme?: Base<P>;
focusTheme?: Base<P>;
disabledTheme?: Base<P>;
} = {}
) => {
const { variants, compoundVariants = [], defaultVariants } = themeConfigProps;

const compounedVariant = compoundVariants?.reduce<{
[key in keyof Required<State<P>>]: string[];
}>(
(
acc,
{
// eslint-disable-next-line @typescript-eslint/no-unused-vars
'className': cvClassName,
'animate': _animate,
':active': _activeCompoundVariant,
':hover': _hoverCompoundVariant,
':focus': _focusCompoundVariant,
':disabled': _disabledCompoundVariant,
...compoundVariantOptions
}
) => {
return Object.entries(compoundVariantOptions).every(([key, value]) =>
Array.isArray(value)
? value.includes(
{
...defaultVariants,
...variantProps,
}[key]
)
: {
...defaultVariants,
...variantProps,
}[key] === value
)
? {
':active': [
...acc[':active'],
...(_activeCompoundVariant?.[keyProperty] || []),
],
':hover': [
...acc[':hover'],
...(_hoverCompoundVariant?.[keyProperty] || []),
],
':focus': [
...acc[':focus'],
...(_focusCompoundVariant?.[keyProperty] || []),
],
':disabled': [
...acc[':disabled'],
...(_disabledCompoundVariant?.[keyProperty] || []),
],
}
: acc;
},
{
':active': [],
':hover': [],
':focus': [],
':disabled': [],
}
);
const result = Object.entries(variantProps).reduce<{
[key in StateName]: string[];
}>(
(acc, [keyVariant, valueVariant]) => {
if (valueVariant !== undefined && valueVariant !== null) {
const variantList = (variants as T)[keyVariant];

const {
':active': _activeCompoundVariant,
':hover': _hoverCompoundVariant,
':focus': _focusCompoundVariant,
':disabled': _disabledCompoundVariant,
} = compounedVariant;

const {
':active': _active,
':hover': _hover,
':focus': _focus,
':disabled': _disabled,
} = (variantList[valueVariant.toString()] ||
{}) satisfies BaseWithState<P>;

acc.active = [
...acc.active,
...(_active?.[keyProperty] || []),
...(_activeCompoundVariant || []),
];

acc.hover = [
...acc.hover,
...(_hover?.[keyProperty] || []),
...(_hoverCompoundVariant || []),
];

acc.focus = [
...acc.focus,
...(_focus?.[keyProperty] || []),
...(_focusCompoundVariant || []),
];

acc.disabled = [
...acc.disabled,
...(_disabled?.[keyProperty] || []),
...(_disabledCompoundVariant || []),
];
}
return acc;
},
{
active: activeTheme?.[keyProperty] || [],
hover: hoverTheme?.[keyProperty] || [],
focus: focusTheme?.[keyProperty] || [],
disabled: disabledTheme?.[keyProperty] || [],
}
);

return result;
};
Loading

0 comments on commit 0968771

Please sign in to comment.