Skip to content

Commit

Permalink
✨ Label - improve style customization
Browse files Browse the repository at this point in the history
  • Loading branch information
JosselinTILLAY committed Dec 19, 2023
1 parent 9767c9b commit 0caa467
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
21 changes: 17 additions & 4 deletions Storybook/components/Label/Label.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ export default {
component: Label,
args: {
type: 'soft',
text: 'text',
},
argTypes: {
text: {
control: { type: 'text' },
},
labelColor: {
control: { type: 'radio' },
options: [
Expand All @@ -32,6 +36,12 @@ export default {
control: { type: 'radio' },
options: ['outlined', 'filled', 'soft'],
},
mainColor: {
control: 'color',
},
backgroundColor: {
control: 'color',
},
},

decorators: [
Expand All @@ -50,9 +60,12 @@ export default {

type Story = StoryObj<LabelProps>;

export const Default: Story = {
args: {
text: 'text',
},
export const Default: Story = (args) => {
const style = {
borderColor: args.mainColor,
backgroundColor: args.backgroundColor,
};
const textStyle = { color: args.mainColor };
return <Label {...args} style={style} textStyle={textStyle} />;
};
Default.parameters = { noSafeArea: false };
15 changes: 12 additions & 3 deletions src/components/label/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { StyleSheet, View, ViewStyle } from 'react-native';
import { StyleSheet, TextStyle, View, ViewStyle } from 'react-native';
import { useTheme } from '../../styles/themes';

import { Body, BodyProps } from '../typography/Body';
Expand All @@ -20,14 +20,22 @@ type OptionnalBodyPropsWithoutSizeAndWeight = Partial<

export interface Props extends OptionnalBodyPropsWithoutSizeAndWeight {
style?: ViewStyle;
textStyle?: TextStyle;
text: string;
type: LabelType;
labelColor?: LabelColor;
size?: 'm' | 's';
}

export const Label = (props: Props) => {
const { style, text, type, labelColor = 'neutral', size = 'm' } = props;
const {
style,
textStyle,
text,
type,
labelColor = 'neutral',
size = 'm',
} = props;
const theme = useTheme();

const transparencyValue = theme.sw.transparency[16];
Expand Down Expand Up @@ -166,8 +174,9 @@ export const Label = (props: Props) => {
...style,
},
text: {
lineHeight: size == 'm' ? 20 : undefined,
lineHeight: size === 'm' ? 20 : undefined,
color,
...textStyle,
},
});
return (
Expand Down

0 comments on commit 0caa467

Please sign in to comment.