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

createText component ignores default styles when no variant used #145

Closed
jackbot opened this issue Mar 29, 2022 · 3 comments
Closed

createText component ignores default styles when no variant used #145

jackbot opened this issue Mar 29, 2022 · 3 comments

Comments

@jackbot
Copy link
Contributor

jackbot commented Mar 29, 2022

I've hunted around in the issues but I can't seem to figure out if I'm missing something obvious here.

It seems like the component created with createText will only use the defaults from the theme if a variant prop is used.

import React from "react";
import { View } from "react-native";
import { createTheme, ThemeProvider } from "@shopify/restyle";
import { createText } from "@shopify/restyle";

const palette = {
  purple: "#8C6FF7",
};

const theme = createTheme({
  colors: {
    textPurple: palette.purple,
  },
  spacing: {
    s: 8,
  },
  breakpoints: {},
  textVariants: {
    defaults: {
      color: "textPurple",
    },
    h1: {
      fontSize: 30,
    },
  },
});

type Theme = typeof theme;
const Text = createText<Theme>();

export default function App() {
  return (
    <ThemeProvider theme={theme}>
      <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
        <Text>I would expect this text to be purple, but it's black</Text>
        <Text variant="h1">
          This text is purple and font size 30 as expected
        </Text>
      </View>
    </ThemeProvider>
  );
}

Screenshot 2022-03-29 at 18 19 02@2x

Am I missing something here?

@sbalay
Copy link
Contributor

sbalay commented Apr 11, 2022

Fixed by #148 in v2.1.0

@sbalay sbalay closed this as completed Apr 11, 2022
@RageOfJustice
Copy link

Hello. The fix is not correct. Now If I dont specify variant (which not necessary according to TS definition, see the screenshot)
image
It throws 2 different errors:

  1. when no textVariants specified:

image

2. when `textVariants` specified but `variant` prop not used for the `Text` component:

image

So, my suggestion is either set variant as required prop in the component or just do not add variant prop when it's not set.

Or 3d option: document that issue in text section. I have wasted 1h trying to solve the problem with digging into the source.

So @sbalay pls reopen the issue

@ghost
Copy link

ghost commented Jun 3, 2022

Please reopen the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants