Skip to content

Commit

Permalink
fix(styled): wrong parser return value
Browse files Browse the repository at this point in the history
  • Loading branch information
wintercounter committed Sep 26, 2021
1 parent 2a59713 commit 565ea85
Showing 1 changed file with 35 additions and 37 deletions.
72 changes: 35 additions & 37 deletions packages/youeye/styled/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CCSSProps, CCSSTransformedFn } from '@cryptic-css/core'
import { StyledComponent, StyledProps, ThemeProviderProps, StyledInterface } from '@types/styled-components'

export type UiProps = StyledProps<CCSSProps>
export type UiPropsWithThemeProviderProps = UiProps & { children: ThemeProviderProps<any>["children"] }
export type UiPropsWithThemeProviderProps = UiProps & { children: ThemeProviderProps<any>['children'] }
export type UiComponent = StyledComponent<'div', any, UiProps>
export type UiComponentFactories = {
[TTag in keyof JSX.IntrinsicElements]: StyledComponent<TTag, any, UiProps>
Expand Down Expand Up @@ -63,7 +63,7 @@ const preserveStyledProps = (target: UiPropsWithThemeProviderProps, source: UiPr

const preservePropsOnCCss = (input, prop, transformedFn, inputObject) => {
return preserveStyledProps(input, inputObject)
};
}

const preservePropsOnChild = (input, prop, transformedFn, inputObject) => {
for (const k in inputObject.child) {
Expand All @@ -72,7 +72,7 @@ const preservePropsOnChild = (input, prop, transformedFn, inputObject) => {
}
}

return inputObject
return input
}

type StyledCCSS = {
Expand All @@ -86,46 +86,44 @@ interface CreateCreator {
(styled: StyledInterface, isNative?: boolean): CreateStyledCCSS
}

export const createCreator: CreateCreator = (
styled,
isNative = typeof navigator != 'undefined' && navigator.product == 'ReactNative'
) => (transformedFn: CCSSTransformedFn, id = 0) => {
const { defaultProps = undefined } = transformedFn.options
const defaultTag = isNative ? 'View' : 'div'
export const createCreator: CreateCreator =
(styled, isNative = typeof navigator != 'undefined' && navigator.product == 'ReactNative') =>
(transformedFn: CCSSTransformedFn, id = 0) => {
const { defaultProps = undefined } = transformedFn.options
const defaultTag = isNative ? 'View' : 'div'

// Just don't do anything with styled stuff
transformedFn
.setProps([
// Just don't do anything with styled stuff
transformedFn.setProps([
[['theme', 'children'], null, [noop], { ccssContext: false }],
[['ccss', 'css'], null, [preservePropsOnCCss, '...'], { ccssContext: false }],
[['child'], null, [preservePropsOnChild, '...'], { ccssContext: false }]
])

const Ui = styled[defaultTag].withConfig({
componentId: `sc-ui${id}`,
displayName: 'Ui',
shouldForwardProp: shouldForwardProp(transformedFn)
})(transformedFn)
Ui.defaultProps = defaultProps

// Recreates supported HTML tags (eg: Ui.section, Ui.ul)
// eslint-disable-next-line no-restricted-syntax
for (const tag in styled) {
if (Object.prototype.hasOwnProperty.call(styled, tag) && isSupportedTag(styled, tag, isNative)) {
try {
Ui[tag] = styled[tag].withConfig({
componentId: `sc-${tag}${id}`,
displayName: `Ui.${tag}`,
shouldForwardProp: shouldForwardProp(transformedFn, exceptionalTags[tag])
})(transformedFn)
// @ts-ignore
Ui[tag].defaultProps = defaultProps
} catch {}
const Ui = styled[defaultTag].withConfig({
componentId: `sc-ui${id}`,
displayName: 'Ui',
shouldForwardProp: shouldForwardProp(transformedFn)
})(transformedFn)
Ui.defaultProps = defaultProps

// Recreates supported HTML tags (eg: Ui.section, Ui.ul)
// eslint-disable-next-line no-restricted-syntax
for (const tag in styled) {
if (Object.prototype.hasOwnProperty.call(styled, tag) && isSupportedTag(styled, tag, isNative)) {
try {
Ui[tag] = styled[tag].withConfig({
componentId: `sc-${tag}${id}`,
displayName: `Ui.${tag}`,
shouldForwardProp: shouldForwardProp(transformedFn, exceptionalTags[tag])
})(transformedFn)
// @ts-ignore
Ui[tag].defaultProps = defaultProps
} catch {}
}
}
}

return {
Ui,
ccss: transformedFn
return {
Ui,
ccss: transformedFn
}
}
}

0 comments on commit 565ea85

Please sign in to comment.