@audira/carbon-react-native 0.0.1-alpha.1 → 0.0.1-alpha.3

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 ADDED
@@ -0,0 +1,232 @@
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)
6
+
7
+ > ⚠️ It is still in development
8
+
9
+ Build React Native apps with component and shared patterns using Carbon.
10
+
11
+ ## Documentation
12
+ 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.
13
+
14
+ You can also see the [example](https://github.com/RakaDoank/carbon-react-native/tree/main/example) app.
15
+
16
+ ## Compatibility
17
+ 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.
18
+
19
+ ## Installation
20
+ This project is not released yet on npm registry. You have to install it manually,
21
+
22
+ With npm
23
+ ```
24
+ npm install @audira/carbon-react-native
25
+ ```
26
+
27
+ pnpm
28
+ ```
29
+ pnpm install @audira/carbon-react-native
30
+ ```
31
+
32
+ yarn
33
+ ```
34
+ yarn add @audira/carbon-react-native
35
+ ```
36
+
37
+ ### Peer Dependencies
38
+
39
+ Install these dependencies on your React Native project, (skip one of these library if already installed)
40
+ - [react-native-reanimated](https://github.com/software-mansion/react-native-reanimated)
41
+ - [react-native-svg](https://github.com/software-mansion/react-native-svg)
42
+ - [@carbon/icons](https://www.npmjs.com/package/@carbon/icons)
43
+ - [@carbon/icon-helpers](https://www.npmjs.com/package/@carbon/icon-helpers)
44
+
45
+ ### Font Installation
46
+ Install the `IBM Plex Sans` font to your project with [react-native-asset](https://www.npmjs.com/package/react-native-asset). Update your `react-native.config.js` file (create it on your root project directory if doesn't exist)
47
+ ```js
48
+ module.exports = {
49
+ assets: [
50
+ './node_modules/@audira/carbon-react-native/assets/fonts/',
51
+ ],
52
+ }
53
+ ```
54
+ Then, run `npx react-native-asset` to link the fonts
55
+
56
+ ## Initialize
57
+ 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>`
58
+ ```tsx
59
+ // Somewhere like in your App.tsx file
60
+ import {
61
+ CarbonReactNative,
62
+ } from '@audira/carbon-react-native'
63
+
64
+ export default function App() {
65
+ return (
66
+ <CarbonReactNative>
67
+ { /* the rest of your react */ }
68
+ </CarbonReactNative>
69
+ )
70
+ }
71
+ ```
72
+
73
+ ## Usage
74
+ ### Components
75
+ Not all components are available yet, but you can test one of this library's component that are available
76
+ ```tsx
77
+ import {
78
+ Button,
79
+ } from '@audira/carbon-react-native'
80
+
81
+ import AddIcon from '@carbon/icons/es/add/20'
82
+
83
+ export default function YourReactComponent() {
84
+ return (
85
+ <Button.PrimaryDanger
86
+ text="Press this"
87
+ icon={ AddIcon }
88
+ />
89
+ )
90
+ }
91
+ ```
92
+ 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.
93
+
94
+ ### Accessing Color Token
95
+ 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`.
96
+ ```tsx
97
+ import {
98
+ useContext,
99
+ } from 'react'
100
+
101
+ import {
102
+ Text,
103
+ ThemeContext,
104
+ } from '@audira/carbon-react-native'
105
+
106
+ export default function YourReactComponent() {
107
+ const themeContext = useContext(ThemeContext)
108
+
109
+ return (
110
+ <Text type="label_01" style={{ color: themeContext.color.support_error }}>
111
+ React Native
112
+ </Text>
113
+ )
114
+ }
115
+ ```
116
+ 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 (-).
117
+
118
+ ### Constants
119
+ 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).
120
+ ```tsx
121
+ import {
122
+ StyleSheet,
123
+ View,
124
+ } from 'react-native'
125
+
126
+ import {
127
+ SpacingConstant,
128
+ } from '@audira/carbon-react-native'
129
+
130
+ export default function YourReactComponent() {
131
+ return (
132
+ <View style={ style.container }>
133
+ { /* other contents */ }
134
+ </View>
135
+ )
136
+ }
137
+
138
+ const style = StyleSheet.create({
139
+ container: {
140
+ paddingHorizontal: SpacingConstant.spacing_05,
141
+ },
142
+ })
143
+ ```
144
+
145
+ ### Change Color Scheme
146
+ `colorScheme`: `gray_10` | `gray_100`
147
+
148
+ This UI library will solve what color scheme on your project natively, with this map
149
+ - light theme -> `gray_10`
150
+ - dark theme -> `gray_100`
151
+
152
+ 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
153
+ ```tsx
154
+ import {
155
+ CarbonReactNative,
156
+ } from '@audira/carbon-react-native'
157
+
158
+ export default function App() {
159
+ return (
160
+ <CarbonReactNative colorScheme="gray_100">
161
+ { /* the rest of your react */ }
162
+ </CarbonReactNative>
163
+ )
164
+ }
165
+ ```
166
+
167
+ ### Override Carbon Color Tokens
168
+ 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.
169
+ > :warning: Be aware of this. All components are made also get the impact of color token change
170
+ ```tsx
171
+ import {
172
+ CarbonReactNative,
173
+ ColorConstant,
174
+ } from '@audira/carbon-react-native'
175
+
176
+ export default function App() {
177
+ return (
178
+ <CarbonReactNative
179
+ overrideColor={{
180
+ ...ColorConstant.Tokens.GRAY_100,
181
+ button_primary: '#9021e5', // as an example, change button_primary from blue originally to purple
182
+ }}
183
+ >
184
+ { /* the rest of your react */ }
185
+ </CarbonReactNative>
186
+ )
187
+ }
188
+ ```
189
+
190
+ **Caveat**, if you fill this prop, `colorScheme` will means nothing, since it depends on whatever your logic here.
191
+
192
+ Another example, you can still follow the light and dark theme by using `gray_10` and `gray_100` and extends it
193
+ ```tsx
194
+ import {
195
+ useColorScheme,
196
+ } from 'react-native'
197
+
198
+ import {
199
+ CarbonReactNative,
200
+ ColorHelper,
201
+ type ThemeType,
202
+ } from '@audira/carbon-react-native'
203
+
204
+ export default function App() {
205
+ const
206
+ nativeColorScheme =
207
+ useColorScheme(),
208
+
209
+ colorScheme =
210
+ ColorHelper.getColorScheme(nativeColorScheme)
211
+
212
+ return (
213
+ <CarbonReactNative
214
+ overrideColor={{
215
+ ...ColorHelper.getColorToken(colorScheme),
216
+ button_primary: customColorToken[colorScheme].button_primary,
217
+ }}
218
+ >
219
+ { /* the rest of your react */ }
220
+ </CarbonReactNative>
221
+ )
222
+ }
223
+
224
+ const customColorToken: Record<ThemeType.ColorScheme, { button_primary: string }> = {
225
+ gray_10: {
226
+ button_primary: '#9021e5',
227
+ },
228
+ gray_100: {
229
+ button_primary: '#a421e5'
230
+ },
231
+ }
232
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audira/carbon-react-native",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.3",
4
4
  "type": "module",
5
5
  "peerDependencies": {
6
6
  "@carbon/icons": ">=11",