@audira/carbon-react-native 0.0.1-alpha.1 → 0.0.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +222 -0
- package/assets/fonts/IBMPlexSans-Bold-Italic.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Bold.ttf +0 -0
- package/assets/fonts/IBMPlexSans-ExtraLight-Italic.ttf +0 -0
- package/assets/fonts/IBMPlexSans-ExtraLight.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Italic.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Light-Italic.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Light.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Medium-Italic.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Medium.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Regular.ttf +0 -0
- package/assets/fonts/IBMPlexSans-SemiBold-Italic.ttf +0 -0
- package/assets/fonts/IBMPlexSans-SemiBold.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Thin-Italic.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Thin.ttf +0 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
Carbon for React Native
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
> This library is completely rewritten and not intended to be the replacement of the official [carbon-react-native](https://github.com/carbon-design-system/carbon-react-native). It is still in development and far from publish released.
|
|
6
|
+
|
|
7
|
+
Build React Native apps with component and shared patterns using Carbon.
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
Documentation available with [docusaurus](https://docusaurus.io/) project on this repository under [docs](https://github.com/RakaDoank/carbon-react-native/tree/main/docs) directory. It's not completed yet, even the library, but it will be documented enough, as soon as the library is ready to use. You can start the docs web project with `npm run start` command in the [docs](https://github.com/RakaDoank/carbon-react-native/tree/main/docs) directory.
|
|
11
|
+
|
|
12
|
+
## Compatibility
|
|
13
|
+
This library is just a pure JavaScript usage in React Native and only depends on the primitive React Native components with [react-native-reanimated](https://github.com/software-mansion/react-native-reanimated) and [react-native-svg](https://github.com/software-mansion/react-native-svg). It should compatible on all platforms available that can be built with React Native, but i cannot sure that. For the web only, [Carbon React](https://react.carbondesignsystem.com) is already there and do its best and solve a lot of accessibility feature.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
This project is not released yet on npm registry. You have to install it manually,
|
|
17
|
+
1. Clone or Download this repository
|
|
18
|
+
2. Install [pnpm](https://github.com/pnpm/pnpm) package manager if it doesn't exist on your system, and do `pnpm install` in this repoistory
|
|
19
|
+
3. Inside this project, run this command to create actual npm package
|
|
20
|
+
```
|
|
21
|
+
npm run create-package-symlink ../to/your/react-native-project
|
|
22
|
+
```
|
|
23
|
+
Change the path argument, it's relative from this repository lives
|
|
24
|
+
|
|
25
|
+
5. In your project directory, install the library by this command
|
|
26
|
+
```
|
|
27
|
+
npm install --save ./.carbon-react-native
|
|
28
|
+
```
|
|
29
|
+
Ensure it is the correct path.
|
|
30
|
+
|
|
31
|
+
6. Install these dependencies on your React Native project, (skip one of these library if already installed)
|
|
32
|
+
- [react-native-reanimated](https://github.com/software-mansion/react-native-reanimated)
|
|
33
|
+
- [react-native-svg](https://github.com/software-mansion/react-native-svg)
|
|
34
|
+
- [@carbon/icons](https://www.npmjs.com/package/@carbon/icons)
|
|
35
|
+
- [@carbon/icon-helpers](https://www.npmjs.com/package/@carbon/icon-helpers)
|
|
36
|
+
|
|
37
|
+
7. Install the `IBM Plex Sans` font to your project with `react-native.config.js` file (create it on your root project directory if doesn't exist)
|
|
38
|
+
```js
|
|
39
|
+
module.exports = {
|
|
40
|
+
assets: [
|
|
41
|
+
'./node_modules/@rakadoank/carbon-react-native/assets/fonts/',
|
|
42
|
+
],
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Initialize
|
|
47
|
+
This library depends on React Context to use the color tokens correctly based on the current color scheme. You have to wrap your whole React App once with `<CarbonReactNative>`
|
|
48
|
+
```tsx
|
|
49
|
+
// Somewhere like in your App.tsx file
|
|
50
|
+
import {
|
|
51
|
+
CarbonReactNative,
|
|
52
|
+
} from '@rakadoank/carbon-react-native'
|
|
53
|
+
|
|
54
|
+
export default function App() {
|
|
55
|
+
return (
|
|
56
|
+
<CarbonReactNative>
|
|
57
|
+
{ /* the rest of your react */ }
|
|
58
|
+
</CarbonReactNative>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
### Components
|
|
65
|
+
Not all components are available yet, but you can test one of this library's component that are available
|
|
66
|
+
```tsx
|
|
67
|
+
import {
|
|
68
|
+
Button,
|
|
69
|
+
} from '@rakadoank/carbon-react-native'
|
|
70
|
+
|
|
71
|
+
import AddIcon from '@carbon/icons/es/add/20'
|
|
72
|
+
|
|
73
|
+
export default function YourReactComponent() {
|
|
74
|
+
return (
|
|
75
|
+
<Button.PrimaryDanger
|
|
76
|
+
text="Press this"
|
|
77
|
+
icon={ AddIcon }
|
|
78
|
+
/>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
While this library is still in development and there is no documentation available, this library is written in TypeScript. You can just refer to this [components source](https://github.com/RakaDoank/carbon-react-native/tree/main/src/components) for a while.
|
|
83
|
+
|
|
84
|
+
### Accessing Color Token
|
|
85
|
+
You can use current color token based on what color scheme which are `Gray 10` and `Gray 100`. It is available by using `ThemeContext` that are already provided by `CarbonReactNative`.
|
|
86
|
+
```tsx
|
|
87
|
+
import {
|
|
88
|
+
useContext,
|
|
89
|
+
} from 'react'
|
|
90
|
+
|
|
91
|
+
import {
|
|
92
|
+
Text,
|
|
93
|
+
ThemeContext,
|
|
94
|
+
} from '@rakadoank/carbon-react-native'
|
|
95
|
+
|
|
96
|
+
export default function YourReactComponent() {
|
|
97
|
+
const themeContext = useContext(ThemeContext)
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<Text type="label_01" style={{ color: themeContext.color.support_error }}>
|
|
101
|
+
React Native
|
|
102
|
+
</Text>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
All components are also made by using `ThemeContext` by the way. All members of the color is same as the official color tokens [here](https://carbondesignsystem.com/elements/color/tokens), but it is using underscore (_) instead of dash (-).
|
|
107
|
+
|
|
108
|
+
### Constants
|
|
109
|
+
You can use the constants are available which are `ColorConstant`, `SpacingConstant`, `TypographyConstant`, and `MotionConstant`. Refer to this [source](https://github.com/RakaDoank/carbon-react-native/tree/main/src/constants).
|
|
110
|
+
```tsx
|
|
111
|
+
import {
|
|
112
|
+
StyleSheet,
|
|
113
|
+
View,
|
|
114
|
+
} from 'react-native'
|
|
115
|
+
|
|
116
|
+
import {
|
|
117
|
+
SpacingConstant,
|
|
118
|
+
} from '@rakadoank/carbon-react-native'
|
|
119
|
+
|
|
120
|
+
export default function YourReactComponent() {
|
|
121
|
+
return (
|
|
122
|
+
<View style={ style.container }>
|
|
123
|
+
{ /* other contents */ }
|
|
124
|
+
</View>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const style = StyleSheet.create({
|
|
129
|
+
container: {
|
|
130
|
+
paddingHorizontal: SpacingConstant.spacing_05,
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Change Color Scheme
|
|
136
|
+
`colorScheme`: `gray_10` | `gray_100`
|
|
137
|
+
|
|
138
|
+
This UI library will solve what color scheme on your project natively, with this map
|
|
139
|
+
- light theme -> `gray_10`
|
|
140
|
+
- dark theme -> `gray_100`
|
|
141
|
+
|
|
142
|
+
If you want override the colorScheme, as an example you only want to use the `gray_100` color scheme (dark mode only), you fill the prop with `gray_100` value
|
|
143
|
+
```tsx
|
|
144
|
+
import {
|
|
145
|
+
CarbonReactNative,
|
|
146
|
+
} from '@rakadoank/carbon-react-native'
|
|
147
|
+
|
|
148
|
+
export default function App() {
|
|
149
|
+
return (
|
|
150
|
+
<CarbonReactNative colorScheme="gray_100">
|
|
151
|
+
{ /* the rest of your react */ }
|
|
152
|
+
</CarbonReactNative>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Override Carbon Color Tokens
|
|
158
|
+
Not recommended to override the color token that are made by Carbon, but you can still override it or just change one of the color token members.
|
|
159
|
+
> :warning: Be aware of this. All components are made also get the impact of color token change
|
|
160
|
+
```tsx
|
|
161
|
+
import {
|
|
162
|
+
CarbonReactNative,
|
|
163
|
+
ColorConstant,
|
|
164
|
+
} from '@rakadoank/carbon-react-native'
|
|
165
|
+
|
|
166
|
+
export default function App() {
|
|
167
|
+
return (
|
|
168
|
+
<CarbonReactNative
|
|
169
|
+
overrideColor={{
|
|
170
|
+
...ColorConstant.Tokens.GRAY_100,
|
|
171
|
+
button_primary: '#9021e5', // as an example, change button_primary from blue originally to purple
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
{ /* the rest of your react */ }
|
|
175
|
+
</CarbonReactNative>
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**Caveat**, if you fill this prop, `colorScheme` will means nothing, since it depends on whatever your logic here.
|
|
181
|
+
|
|
182
|
+
Another example, you can still follow the light and dark theme by using `gray_10` and `gray_100` and extends it
|
|
183
|
+
```tsx
|
|
184
|
+
import {
|
|
185
|
+
useColorScheme,
|
|
186
|
+
} from 'react-native'
|
|
187
|
+
|
|
188
|
+
import {
|
|
189
|
+
CarbonReactNative,
|
|
190
|
+
ColorHelper,
|
|
191
|
+
type ThemeType,
|
|
192
|
+
} from '@rakadoank/carbon-react-native'
|
|
193
|
+
|
|
194
|
+
export default function App() {
|
|
195
|
+
const
|
|
196
|
+
nativeColorScheme =
|
|
197
|
+
useColorScheme(),
|
|
198
|
+
|
|
199
|
+
colorScheme =
|
|
200
|
+
ColorHelper.getColorScheme(nativeColorScheme)
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<CarbonReactNative
|
|
204
|
+
overrideColor={{
|
|
205
|
+
...ColorHelper.getColorToken(colorScheme),
|
|
206
|
+
button_primary: customColorToken[colorScheme].button_primary,
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
{ /* the rest of your react */ }
|
|
210
|
+
</CarbonReactNative>
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const customColorToken: Record<ThemeType.ColorScheme, { button_primary: string }> = {
|
|
215
|
+
gray_10: {
|
|
216
|
+
button_primary: '#9021e5',
|
|
217
|
+
},
|
|
218
|
+
gray_100: {
|
|
219
|
+
button_primary: '#a421e5'
|
|
220
|
+
},
|
|
221
|
+
}
|
|
222
|
+
```
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|