Hi,
I’m creating a web & native React library about a responsive UI methodology called Every Layout.
First, I coded it in Typescript, then I discovered ReScript . I’m converting it.
I need to use the npm package @tamagui/core. The problem is its Typescript components have many of types, the each type have dozens of parameters (CSS and React Native). An example below.
My component Cluster.tsx component needs: type StackProps and component:
import React from 'react';
import { Stack, StackProps, Text } from '@tamagui/core';
import { toDimensionValue } from './utils';
export type CenterProps = StackProps & {
maxWidth?: string | number;
centerText?: boolean;
gutters?: string | number;
intrinsic?: boolean;
};
/**
* The Center component is used for horizontally centering a block-level element,
* with a max-width value representing the typographic measure.
*
* More on Every Layout Center.
*/
export const Center: React.FC<CenterProps> = ({
children,
maxWidth,
centerText = false,
gutters,
intrinsic = false,
...props
}) => {
return (
<Stack
maxWidth={toDimensionValue(maxWidth)}
marginHorizontal="auto"
paddingHorizontal={toDimensionValue(gutters)}
alignItems={intrinsic ? 'center' : undefined}
flexDirection={intrinsic ? 'column' : undefined}
{...props}
>
{centerText ? <Text textAlign="center">{children}</Text> : children}
</Stack>
);
};
But I have problems in ReScript. I struggle to bind @tamagui/core to ReScript, as you can see in Tamagui.res github(dot)com/guillempuche/every-layout-react/blob/main/packages/react-tamagui/src/bindings/Tamagui.res and Cluster.res:
@module("@tamagui/core")
external // external stack: React.component<{..}> = "Stack"
stack: React.component<'props> = ({..}) => React.component<'props> = "Stack"
@module("@tamagui/core") external stack: React.element = "Stack"
@module("@tamagui/web")
external stack: ()
@module("@tamagui/core")
external text: React.component<{..}> = "Text"
module Stack = {
@module("@tamagui/core") @react.component external make: {..} => React.element = "Stack"
}
Here you can have a look at the complex @tamagui/core code:
import { validStyles } from '@tamagui/helpers'
import { stackDefaultStyles } from '../constants/constants'
import { createComponent } from '../createComponent'
import type { StackProps, StackPropsBase, TamaguiElement } from '../types'
export type Stack = TamaguiElement
export const Stack = createComponent<StackProps, Stack, StackPropsBase>({
acceptsClassName: true,
defaultProps: stackDefaultStyles,
validStyles,
})
- StacksProps link: github(dot)com/tamagui/tamagui/blob/master/packages/web/types/types.d.ts#L754 type
export type StackStyleProps =
WithThemeShorthandsPseudosMediaAnimation<StackStylePropsBase>
export type StackPropsBase = StackNonStyleProps &
WithThemeAndShorthands<StackStylePropsBase>
export type StackProps = StackNonStyleProps & StackStyleProps
How can I bind Javascript/Typescript that can have dozens of paramaters? Do I need to convert them entiretly? And the fastest way?
Thanks