Skip to content

Commit bfabb1a

Browse files
katsuhira02Danil
andauthored
add labels component (#64)
Co-authored-by: Danil <[email protected]>
1 parent 60000ae commit bfabb1a

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

App.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from 'react'
22
import { Text } from 'react-native'
33
import { StyleSheet, ScrollView, View } from 'react-native'
44
import { DARK, WHITE } from './src/constants'
5-
import { Button, Space, Switch } from './src/components'
5+
import { Button, Space, Switch, Labels } from './src/components'
66

77
const styles = StyleSheet.create({
88
container: {
@@ -38,6 +38,14 @@ export default function App({}){
3838
<Space height={15} />
3939
<Switch isValue={isEnabled} onValueChange={toggleSwitch}/>
4040
<Space height={30} />
41+
<Text style={textStyle}>Labels</Text>
42+
<Space height={15} />
43+
<Labels isSaleOrNew={true} title='-20%'/>
44+
<Space height={15} />
45+
<Labels isSaleOrNew={false} title='NEW'/>
46+
<Space height={15} />
47+
<Labels isSaleOrNew={true} title='HOT'/>
48+
<Space height={30} />
4149
</View>
4250
)
4351
}

src/components/Labels/index.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react'
2+
import { BLACK, SALE, WHITE } from '../../constants'
3+
import {StyleSheet, Text, View} from 'react-native'
4+
5+
const styles = StyleSheet.create({
6+
container: {
7+
width: 40,
8+
height: 24,
9+
borderRadius: 29
10+
},
11+
colorDark: {
12+
backgroundColor: BLACK
13+
},
14+
color: {
15+
backgroundColor: SALE
16+
},
17+
textStyle: {
18+
alignItems: 'center',
19+
alignSelf: 'center',
20+
color: WHITE,
21+
fontSize: 15
22+
}
23+
})
24+
25+
interface LabelsT {
26+
isSaleOrNew: boolean,
27+
title: string
28+
}
29+
30+
function Labels ({isSaleOrNew, title}: LabelsT){
31+
const { container, colorDark, color, textStyle } = styles
32+
const saleOrNew = isSaleOrNew ? color : colorDark
33+
34+
return (
35+
<View style={[saleOrNew, container]}>
36+
<Text style={textStyle}>{title}</Text>
37+
</View>
38+
)
39+
}
40+
41+
export { Labels }

src/components/Switch/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import React, {useState} from 'react'
33
import { View, Switch as Swi, StyleSheet } from "react-native"
44
import { SUCCESS, GRAY, GRAY_OPACITY } from '../../constants'
55

6+
const styles = StyleSheet.create({
7+
container: {
8+
alignItems: "center",
9+
justifyContent: "center"
10+
}
11+
})
12+
613
interface SwitchT {
714
isValue: boolean,
815
isDisable?: boolean,
@@ -23,12 +30,5 @@ function Switch ({isValue, isDisable, onValueChange }: SwitchT){
2330
</View>
2431
)
2532
}
26-
27-
const styles = StyleSheet.create({
28-
container: {
29-
alignItems: "center",
30-
justifyContent: "center"
31-
}
32-
})
3333

3434
export { Switch }

src/components/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './Button'
22
export * from './Space'
3-
export * from './Switch'
3+
export * from './Switch'
4+
export * from './Labels'

0 commit comments

Comments
 (0)