thabti / react-native-css

Style React-Native components with css
MIT License
769 stars 66 forks source link

Using dash in naming #33

Closed abeikverdi closed 8 years ago

abeikverdi commented 8 years ago

React-native StyleSheet apparently doesn't accept dash "-" in the names unlike css. React interprets dash as an indicator for multiple classes. So react-native-css shouldn't just create names with dashes in the output file. I would say it should output an error when generating js file.

thabti commented 8 years ago

@abeikverdi This project is a community and is open source, we accept pull requests. Can I get a more details, like code examples?

abeikverdi commented 8 years ago

Lets say we have a css like this:

.class-name {
    attribute1: attribute1;
    attribute2: attribute2;
}

The result after using react-native-css would be :

const styles = StyleSheet.create({
    'class-name': {
    attribute1: 'attribute1';
    attribute2: 'attribute2';
  }

And after you assign this to an element in React like this example:

<Text style={styles.class-name}>

I assume RN takes class and name as two classes instead of one class and creates an error.

abeikverdi commented 8 years ago

I am not sure how this library should convert css classes with dash. Perhaps a class rename?

thabti commented 8 years ago

you can do <Text style={styles.['class-name']}> ? while the syntax isn't pretty, it's common way to handle dashes.

@alexmick thoughts?

alexmick commented 8 years ago

Indeed, the plugin does not rewrite your class names so if you call your class class-name you have to call it by styles['class-name'] as @sabeurthabti pointed out. The way around this is to camelCase you classes like so

.className {
    attribute1: attribute1;
    attribute2: attribute2;
}

Maybe we could force camelCasing of class names but I have a feeling this would be a confusing behaviour...

PS: I edited your comment @abeikverdi to add the quotes around class-name in the second snippet because this is what react-native-css will output (I just checked)

abeikverdi commented 8 years ago

@sabeurthabti Ah I see. Didnt know that I can put the classes inside brackets like that. @alexmick I agree it could be confusing. Cheers