Skip to content

Commit

Permalink
feat(plasma-new-hope): Add wrapper for layout with default props
Browse files Browse the repository at this point in the history
  • Loading branch information
neretin-trike committed Sep 25, 2023
1 parent 42e38cc commit c9d4247
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/plasma-new-hope/scripts/replace-linaria_sc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ perl -p -i -e "s/import { css } from '\@linaria\/core'/import { css } from 'styl

rm -rf src-sc/engines/linaria.tsx
perl -p -i -e "s/import { css as cssLibrary } from '\@linaria\/core'/import { css as cssLibrary } from 'styled-components'/g" src-sc/engines/index.ts
perl -p -i -e "s/linaria/styled-components/g" src-sc/engines/index.ts src-sc/engines/common.ts
perl -p -i -e "s/linaria/styled-components/g" src-sc/engines/index.ts src-sc/engines/common.tsx

Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@ export function component<
>(
config: ComponentConfig<Tag, VariantList, VariantsProps, LayoutProps>,
): React.FunctionComponent<VariantsProps & LayoutProps> {
return config.layout(_component((config as unknown) as ComponentConfig));
const Comp = config.layout(_component((config as unknown) as ComponentConfig));

return React.forwardRef<VariantsProps & LayoutProps, any>((props, ref) => (
<Comp {...config?.defaults} {...props} ref={ref} />
));
}
4 changes: 2 additions & 2 deletions packages/plasma-new-hope/src/engines/linaria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import type { ComponentConfig, HTMLAnyAttributes } from './types';

/* eslint-disable no-underscore-dangle */
export const _component = (componentConfig: ComponentConfig) => {
const { tag, base, defaults, name } = componentConfig;
const { tag, base, name } = componentConfig;
const staticVariants = getStaticVariants(componentConfig);
const dynamicVariants = getDynamicVariants(componentConfig);
const Root = tag as React.ElementType;

const component = forwardRef<HTMLElement, HTMLAnyAttributes>((props, ref) => {
const { className, ...rest } = props;
const variants = dynamicVariants({ ...defaults, ...rest });
const variants = dynamicVariants(rest);
const cls = cx(className, base, ...staticVariants, ...variants);

// styled-components do it inside
Expand Down
4 changes: 2 additions & 2 deletions packages/plasma-new-hope/src/engines/styled-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export { styled, css };

/* eslint-disable no-underscore-dangle */
export const _component = (componentConfig: ComponentConfig) => {
const { tag, base, defaults } = componentConfig;
const { tag, base } = componentConfig;
const staticVariants = getStaticVariants(componentConfig);
const dynamicVariants = getDynamicVariants(componentConfig);

Expand All @@ -18,5 +18,5 @@ export const _component = (componentConfig: ComponentConfig) => {
${dynamicVariants}
`;

return forwardRef<HTMLElement, HTMLAnyAttributes>((props, ref) => <Root {...defaults} {...props} ref={ref} />);
return forwardRef<HTMLElement, HTMLAnyAttributes>((props, ref) => <Root {...props} ref={ref} />);
};

0 comments on commit c9d4247

Please sign in to comment.