@ds-autonomie/react-native 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @ds-autonomie/react-native
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f2698bb: `Toggle`: implementation du composant Toggle
package/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2023 Caisse nationale de solidarité pour l'autonomie
2
+ Copyright (c) 2020 A Beautiful Site, LLC
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ // src/components/icon/Icon.tsx
2
+ import MaterialIcons from "react-native-vector-icons/MaterialIcons";
3
+ function Icon({ size = 16, ...restProps }) {
4
+ return <MaterialIcons
5
+ {...restProps}
6
+ size={size}
7
+ selectable={false}
8
+ importantForAccessibility="no-hide-descendants"
9
+ accessibilityElementsHidden
10
+ />;
11
+ }
12
+
13
+ export {
14
+ Icon
15
+ };
@@ -0,0 +1,42 @@
1
+ // src/components/toggle/Toggle.styles.ts
2
+ import { color } from "@ds-autonomie/assets/source/design-tokens.tokens.json";
3
+ import { StyleSheet } from "react-native";
4
+ var styles = StyleSheet.create({
5
+ toggle: {
6
+ width: 51,
7
+ height: 31,
8
+ padding: 2,
9
+ borderRadius: 100,
10
+ elevation: 3,
11
+ position: "relative"
12
+ },
13
+ toggleEnabled: {
14
+ backgroundColor: color.primitives.green[500].value
15
+ },
16
+ toggleDisabled: {
17
+ backgroundColor: color.primitives.neutral[400].value
18
+ },
19
+ circle: {
20
+ borderRadius: 100,
21
+ backgroundColor: color.primitives.neutral[100].value,
22
+ width: 27,
23
+ height: 27,
24
+ top: 0,
25
+ boxShadow: "0px 3px 1px 0px #0000000F",
26
+ alignItems: "center",
27
+ justifyContent: "center"
28
+ },
29
+ image: {
30
+ height: 16,
31
+ width: 16
32
+ }
33
+ });
34
+ function getToggleStyle(isOn) {
35
+ const additionalStyle = isOn ? styles.toggleEnabled : styles.toggleDisabled;
36
+ return { ...styles.toggle, ...additionalStyle };
37
+ }
38
+
39
+ export {
40
+ styles,
41
+ getToggleStyle
42
+ };
@@ -0,0 +1,82 @@
1
+ import {
2
+ Icon
3
+ } from "./chunk.4EJ4MEUR.js";
4
+ import {
5
+ getToggleStyle,
6
+ styles
7
+ } from "./chunk.CZ5Y2AVH.js";
8
+
9
+ // src/components/toggle/Toggle.tsx
10
+ import React, { useEffect, useState } from "react";
11
+ import {
12
+ Pressable
13
+ } from "react-native";
14
+ import Animated, {
15
+ withSpring,
16
+ useAnimatedStyle
17
+ } from "react-native-reanimated";
18
+ var TOGGLE_END_POSITION = 20;
19
+ var TOGGLE_START_POSITION = 0;
20
+ var Toggle = React.forwardRef(function Toggle2({ value = false, disabled = false, style, onValueChange, ...restProps }, ref) {
21
+ const [checked, setChecked] = useState(value);
22
+ const toggleStyle = getToggleStyle(checked);
23
+ useEffect(
24
+ function onValueUpdate() {
25
+ setChecked(value);
26
+ },
27
+ [value]
28
+ );
29
+ function handlePress() {
30
+ if (disabled) {
31
+ return;
32
+ }
33
+ const newChecked = !checked;
34
+ onValueChange?.(newChecked);
35
+ setChecked(newChecked);
36
+ }
37
+ const toggleAnimatedStyles = useAnimatedStyle(
38
+ () => ({
39
+ transform: [
40
+ {
41
+ translateX: withSpring(
42
+ checked ? TOGGLE_END_POSITION : TOGGLE_START_POSITION,
43
+ {
44
+ duration: 400,
45
+ stiffness: 30,
46
+ dampingRatio: 2
47
+ }
48
+ )
49
+ }
50
+ ]
51
+ }),
52
+ [checked]
53
+ );
54
+ return <Pressable
55
+ ref={ref}
56
+ {...restProps}
57
+ accessibilityLabel="switch"
58
+ accessibilityRole="switch"
59
+ accessibilityState={{ checked, disabled }}
60
+ accessible
61
+ aria-checked={checked}
62
+ aria-disabled={disabled}
63
+ aria-pressed={checked}
64
+ onPress={handlePress}
65
+ role="switch"
66
+ style={[toggleStyle, style]}
67
+ ><Animated.View
68
+ accessible={false}
69
+ focusable={false}
70
+ style={[styles.circle, toggleAnimatedStyles]}
71
+ >{checked ? <CheckedIcon /> : <DefaultIcon />}</Animated.View></Pressable>;
72
+ });
73
+ function CheckedIcon() {
74
+ return <Icon name="check" color="hsla(120, 1%, 15%, 1)" />;
75
+ }
76
+ function DefaultIcon() {
77
+ return <Icon name="close" color="hsla(0, 0%, 91%, 1)" />;
78
+ }
79
+
80
+ export {
81
+ Toggle
82
+ };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ export interface IconProps {
3
+ name: string;
4
+ size?: number;
5
+ color: string;
6
+ }
7
+ export declare function Icon({ size, ...restProps }: IconProps): React.JSX.Element;
@@ -0,0 +1,6 @@
1
+ import {
2
+ Icon
3
+ } from "../../chunks/chunk.4EJ4MEUR.js";
4
+ export {
5
+ Icon
6
+ };
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import { StyleProp, ViewStyle, PressableProps, View } from 'react-native';
3
+ type OmittedPressableProps = 'accessibilityLabel' | 'accessibilityRole' | 'accessibilityState' | 'accessible' | 'aria-checked' | 'aria-disabled' | 'aria-pressed' | 'style' | 'onPress' | 'children' | 'role';
4
+ export type ToggleProps = {
5
+ /**
6
+ * When set to `true`, component is checked.
7
+ * @default false
8
+ */
9
+ value?: boolean;
10
+ /**
11
+ * When set to `true`, component is disabled.
12
+ * @default false
13
+ */
14
+ disabled?: boolean;
15
+ /**
16
+ * If `style` is defined, it will extend the container style.
17
+ * If a similar property is defined, the new property will overwrite the old one.
18
+ */
19
+ style?: StyleProp<ViewStyle>;
20
+ /**
21
+ * Callback when component is pressed.
22
+ * @param {boolean} value
23
+ */
24
+ onValueChange: (state: boolean) => void;
25
+ } & Omit<PressableProps, OmittedPressableProps>;
26
+ export declare const Toggle: React.ForwardRefExoticComponent<{
27
+ /**
28
+ * When set to `true`, component is checked.
29
+ * @default false
30
+ */
31
+ value?: boolean | undefined;
32
+ /**
33
+ * When set to `true`, component is disabled.
34
+ * @default false
35
+ */
36
+ disabled?: boolean | undefined;
37
+ /**
38
+ * If `style` is defined, it will extend the container style.
39
+ * If a similar property is defined, the new property will overwrite the old one.
40
+ */
41
+ style?: StyleProp<ViewStyle>;
42
+ /**
43
+ * Callback when component is pressed.
44
+ * @param {boolean} value
45
+ */
46
+ onValueChange: (state: boolean) => void;
47
+ } & Omit<PressableProps, OmittedPressableProps> & React.RefAttributes<View>>;
48
+ export {};
@@ -0,0 +1,8 @@
1
+ import {
2
+ Toggle
3
+ } from "../../chunks/chunk.NNC6C337.js";
4
+ import "../../chunks/chunk.4EJ4MEUR.js";
5
+ import "../../chunks/chunk.CZ5Y2AVH.js";
6
+ export {
7
+ Toggle
8
+ };
@@ -0,0 +1,39 @@
1
+ export declare const styles: {
2
+ toggle: {
3
+ width: number;
4
+ height: number;
5
+ padding: number;
6
+ borderRadius: number;
7
+ elevation: number;
8
+ position: "relative";
9
+ };
10
+ toggleEnabled: {
11
+ backgroundColor: string;
12
+ };
13
+ toggleDisabled: {
14
+ backgroundColor: string;
15
+ };
16
+ circle: {
17
+ borderRadius: number;
18
+ backgroundColor: string;
19
+ width: number;
20
+ height: number;
21
+ top: number;
22
+ boxShadow: string;
23
+ alignItems: "center";
24
+ justifyContent: "center";
25
+ };
26
+ image: {
27
+ height: number;
28
+ width: number;
29
+ };
30
+ };
31
+ export declare function getToggleStyle(isOn: boolean): {
32
+ backgroundColor: string;
33
+ width: number;
34
+ height: number;
35
+ padding: number;
36
+ borderRadius: number;
37
+ elevation: number;
38
+ position: "relative";
39
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ getToggleStyle,
3
+ styles
4
+ } from "../../chunks/chunk.CZ5Y2AVH.js";
5
+ export {
6
+ getToggleStyle,
7
+ styles
8
+ };
@@ -0,0 +1,2 @@
1
+ export { Toggle } from './components/toggle/Toggle';
2
+ export * from './utils';
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import {
2
+ Toggle
3
+ } from "./chunks/chunk.NNC6C337.js";
4
+ import "./chunks/chunk.4EJ4MEUR.js";
5
+ import "./chunks/chunk.CZ5Y2AVH.js";
6
+
7
+ // src/utils/useFonts.ts
8
+ import { useFonts as useExpoFonts } from "expo-font";
9
+ function useFonts(map) {
10
+ return useExpoFonts(map);
11
+ }
12
+ export {
13
+ Toggle,
14
+ useFonts
15
+ };
@@ -0,0 +1 @@
1
+ export * from './useFonts';
@@ -0,0 +1,17 @@
1
+ import { FontSource } from 'expo-font';
2
+ interface FontMap {
3
+ 'Cabin-Regular': FontSource;
4
+ 'Cabin-Italic': FontSource;
5
+ 'Cabin-Bold': FontSource;
6
+ 'Cabin-BoldItalic': FontSource;
7
+ 'Montserrat-Regular': FontSource;
8
+ 'Montserrat-Italic': FontSource;
9
+ 'Montserrat-Bold': FontSource;
10
+ 'Montserrat-BoldItalic': FontSource;
11
+ [name: string]: FontSource;
12
+ }
13
+ /**
14
+ * @see https://docs.expo.dev/versions/latest/sdk/font
15
+ */
16
+ export declare function useFonts(map: FontMap): [boolean, Error | null];
17
+ export {};
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@ds-autonomie/react-native",
3
+ "version": "0.1.0",
4
+ "author": "CNSA",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./dist/components": "./dist/components/*"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "CHANGELOG.md",
19
+ "LICENSE"
20
+ ],
21
+ "repository": {
22
+ "directory": "packages/react-native",
23
+ "type": "git",
24
+ "url": "https://github.com/cnsa-fr/design-system.git"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "peerDependencies": {
30
+ "react": "^18.2.0",
31
+ "react-native": "^0.72.6",
32
+ "react-native-vector-icons": "^10.0.1",
33
+ "react-native-reanimated": "^3.3.0",
34
+ "expo-font": "^11.4.0",
35
+ "@ds-autonomie/assets": "1.1.1"
36
+ },
37
+ "devDependencies": {
38
+ "@storybook/react-native": "6.5.7",
39
+ "@testing-library/jest-native": "5.4.3",
40
+ "@testing-library/react-native": "12.3.0",
41
+ "@types/jest": "29.5.5",
42
+ "@types/react": "18.2.33",
43
+ "@types/react-native-vector-icons": "6.4.16",
44
+ "@types/react-test-renderer": "18.0.2",
45
+ "jest": "29.2.1",
46
+ "react-native-accessibility-engine": "3.2.0",
47
+ "react-test-renderer": "18.2.0",
48
+ "ts-jest": "29.1.1",
49
+ "@ds-autonomie/eslint-config": "2.0.0"
50
+ },
51
+ "scripts": {
52
+ "ts:check": "tsc --noEmit",
53
+ "start": "pnpm run '/^watch:.*/'",
54
+ "build": "node scripts/build.js --types",
55
+ "watch:types": "tsc --project tsconfig.prod.json --watch",
56
+ "watch:code": "node scripts/build.js --types --watch",
57
+ "test": "jest",
58
+ "test:watch": "jest --watch",
59
+ "test:coverage": "jest --collectCoverage --coverageDirectory=\"./coverage\""
60
+ }
61
+ }