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

✨ Label - add customization #152

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading