Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Feature/show2 233 segmented control #625

Merged
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
1 change: 1 addition & 0 deletions apps/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@radix-ui/react-tabs": "^0.1.1",
"@react-native-async-storage/async-storage": "^1.15.11",
"@react-native-community/netinfo": "7.1.3",
"@react-native-segmented-control/segmented-control": "^2.4.0",
"@react-navigation/bottom-tabs": "^6.0.9",
"@react-navigation/native": "^6.0.6",
"@react-navigation/native-stack": "^6.2.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const getStories = () => {
require("../../../packages/design-system/tabs/tabs.stories.tsx"),
require("../../../packages/design-system/text/text.stories.tsx"),
require("../../../packages/design-system/toast/toast.stories.tsx"),
require("../../../packages/design-system/segmented-control/segmented-control.stories.tsx"),
];
};

Expand Down
1 change: 1 addition & 0 deletions apps/storybook-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@react-native-async-storage/async-storage": "~1.15.0",
"@react-native-community/datetimepicker": "4.0.0",
"@react-native-community/slider": "4.1.12",
"@react-native-segmented-control/segmented-control": "^2.4.0",
"@storybook/addon-actions": "^6.3.12",
"@storybook/addon-controls": "^6.3.12",
"@storybook/addon-ondevice-actions": "^6.0.1-alpha.6",
Expand Down
40 changes: 40 additions & 0 deletions packages/design-system/segmented-control/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import RNSegmentedControl from "@react-native-segmented-control/segmented-control";
import { useCallback } from "react";
import {
NativeSegmentedControlIOSChangeEvent,
NativeSyntheticEvent,
} from "react-native";
import { colors } from "design-system/tailwind/colors";
import { useIsDarkMode } from "design-system/hooks";
import { tw } from "design-system/tailwind";

type SegmentedControlProps = {
values: Array<string>;
selectedIndex: number;
onChange: (newIndex: number) => void;
};

export const SegmentedControl = (props: SegmentedControlProps) => {
const { values, selectedIndex, onChange } = props;
const handleChange = useCallback(
(e: NativeSyntheticEvent<NativeSegmentedControlIOSChangeEvent>) => {
onChange?.(e.nativeEvent.selectedSegmentIndex);
},
[onChange]
);

const isDark = useIsDarkMode();

return (
<RNSegmentedControl
values={values}
selectedIndex={selectedIndex}
onChange={handleChange}
style={tw.style("rounded-lg")}
backgroundColor={isDark ? colors.gray[900] : colors.gray[100]}
tintColor={isDark ? colors.white : colors.gray[900]}
fontStyle={tw.style("font-bold dark:text-gray-400 text-gray-600")}
activeFontStyle={tw.style("font-bold dark:text-gray-900 text-white")}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Meta } from "@storybook/react";
import { SegmentedControl } from "./index";
import { useState } from "react";

export default {
component: SegmentedControl,
title: "Components/SegmentedControl",
} as Meta;

export const Primary: React.VFC<{}> = () => {
const [selected, setSelected] = useState(0);
return (
<SegmentedControl
values={["LABEL 1", "LABEL 2", "LABEL 3"]}
onChange={setSelected}
selectedIndex={selected}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControlTab.js b/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControlTab.js
index 85bb622..5eddb89 100644
--- a/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControlTab.js
+++ b/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControlTab.js
@@ -14,7 +14,7 @@ import {
View,
useColorScheme,
} from 'react-native';
-
+import { Pressable } from "design-system/pressable-scale"
import type {FontStyle, ViewStyle} from './types';

type Props = $ReadOnly<{|
@@ -83,8 +83,8 @@ export const SegmentedControlTab = ({
};

return (
- <TouchableOpacity
- style={[styles.container, tabStyle]}
+ <Pressable
+ containerStyle={[styles.container, tabStyle]}
disabled={!enabled}
onPress={onSelect}
accessibilityState={{selected: selected, disabled: !enabled}}>
@@ -97,7 +97,7 @@ export const SegmentedControlTab = ({
<Text style={[idleStyle, selected && activeStyle]}>{value}</Text>
)}
</View>
- </TouchableOpacity>
+ </Pressable>
);
};

5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,11 @@
resolved "https://registry.yarnpkg.com/@react-native-community/slider/-/slider-4.1.12.tgz#279ff7bbe487af92ad95ec758a029a54569e2a62"
integrity sha512-CiuLZ2orueBiWHYxfaJF57jQY6HY2Q3z5pdAE4MKH8EqIImr/jgDJrJ/UxOVZHK1Ng9P+XlGIKfVIcuWZ6guuA==

"@react-native-segmented-control/segmented-control@^2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@react-native-segmented-control/segmented-control/-/segmented-control-2.4.0.tgz#0a88f22ad2c0fe07ecc002ee1e5d62c55a3dd0ae"
integrity sha512-2s1AaT6xk/Do5s6u7ioCXucqesAt02NQlLKBOM28dJWI7PTH9o89x6AwsGHIeMkTe4nQ6iENiJKzO7Y3SGG9Ew==

"@react-native/[email protected]":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@react-native/assets/-/assets-1.0.0.tgz#c6f9bf63d274bafc8e970628de24986b30a55c8e"
Expand Down