@bitrise/bitkit 12.11.6 → 12.12.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "12.11.6",
4
+ "version": "12.12.0",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -0,0 +1,7 @@
1
+ import { UseRadioGroupReturn } from '@chakra-ui/react';
2
+ import { createContext } from '@chakra-ui/react-utils';
3
+
4
+ export interface ContentSwitcherContextType {
5
+ getRadioProps: UseRadioGroupReturn['getRadioProps'];
6
+ }
7
+ export const [ContentSwitcherContext, useContentSwitcherContext] = createContext<ContentSwitcherContextType>();
@@ -0,0 +1,47 @@
1
+ import { createMultiStyleConfigHelpers } from '@chakra-ui/styled-system';
2
+
3
+ const itemHelpers = createMultiStyleConfigHelpers(['container', 'item']);
4
+
5
+ const ContentSwitcherTheme = itemHelpers.defineMultiStyleConfig({
6
+ baseStyle: {
7
+ container: {
8
+ display: 'flex',
9
+ width: '100%',
10
+ backgroundColor: 'neutral.95',
11
+ gap: '4',
12
+ borderRadius: '8',
13
+ padding: '4',
14
+ },
15
+ item: {
16
+ flexGrow: 1,
17
+ paddingX: '0.375rem',
18
+ cursor: 'pointer',
19
+ fontSize: '3',
20
+ lineHeight: '2.375rem',
21
+ color: 'purple.10',
22
+ textAlign: 'center',
23
+ border: '1px solid',
24
+ borderColor: 'transparent',
25
+ borderRadius: '4',
26
+ _checked: {
27
+ fontWeight: 'demiBold',
28
+ color: 'purple.40',
29
+ backgroundColor: 'neutral.100',
30
+ borderColor: 'separator.primary',
31
+ _hover: {
32
+ backgroundColor: 'neutral.100',
33
+ borderColor: 'separator.primary',
34
+ },
35
+ },
36
+ _focus: {
37
+ boxShadow: 'outline',
38
+ },
39
+ _hover: {
40
+ backgroundColor: 'neutral.93',
41
+ borderColor: 'neutral.93',
42
+ },
43
+ },
44
+ },
45
+ });
46
+
47
+ export default ContentSwitcherTheme;
@@ -0,0 +1,40 @@
1
+ import { useMemo } from 'react';
2
+ import { useMultiStyleConfig, useRadioGroup, UseRadioGroupProps } from '@chakra-ui/react';
3
+ import Box, { BoxProps } from '../Box/Box';
4
+ import { ContentSwitcherContext, ContentSwitcherContextType } from './ContentSwitcher.context';
5
+
6
+ export type ContentSwitcherProps = BoxProps & UseRadioGroupProps;
7
+
8
+ /**
9
+ * This is a custom radio button group, based on: https://chakra-ui.com/docs/components/radio/usage#custom-radio-buttons.
10
+ */
11
+ const ContentSwitcher = (props: ContentSwitcherProps) => {
12
+ const { defaultValue, isDisabled, name, onChange, value, ...rest } = props;
13
+
14
+ const { getRootProps, getRadioProps } = useRadioGroup({
15
+ defaultValue,
16
+ isDisabled,
17
+ name,
18
+ onChange,
19
+ value,
20
+ });
21
+
22
+ const ctx = useMemo<ContentSwitcherContextType>(
23
+ () => ({
24
+ getRadioProps,
25
+ }),
26
+ [getRadioProps],
27
+ );
28
+
29
+ const group = getRootProps();
30
+
31
+ const theme = useMultiStyleConfig('ContentSwitcher');
32
+
33
+ return (
34
+ <ContentSwitcherContext value={ctx}>
35
+ <Box __css={theme.container} {...group} {...rest} />
36
+ </ContentSwitcherContext>
37
+ );
38
+ };
39
+
40
+ export default ContentSwitcher;
@@ -0,0 +1,27 @@
1
+ import { useMultiStyleConfig, useRadio } from '@chakra-ui/react';
2
+ import Box from '../Box/Box';
3
+ import { useContentSwitcherContext } from './ContentSwitcher.context';
4
+
5
+ export interface ContentSwitcherItemProps {
6
+ children: string;
7
+ value: string;
8
+ }
9
+
10
+ const ContentSwitcherItem = (props: ContentSwitcherItemProps) => {
11
+ const { getRadioProps } = useContentSwitcherContext();
12
+
13
+ const { children, value } = props;
14
+
15
+ const { getInputProps, getCheckboxProps } = useRadio(getRadioProps({ value }));
16
+
17
+ const theme = useMultiStyleConfig('ContentSwitcher');
18
+
19
+ return (
20
+ <Box as="label" __css={theme.item} {...getCheckboxProps()}>
21
+ <input {...getInputProps()} />
22
+ {children}
23
+ </Box>
24
+ );
25
+ };
26
+
27
+ export default ContentSwitcherItem;
package/src/index.ts CHANGED
@@ -269,3 +269,9 @@ export {
269
269
  } from './Components/Sidebar/Sidebar';
270
270
  export { default as SidebarItem } from './Components/Sidebar/SidebarItem';
271
271
  export { SidebarItemIcon, SidebarItemLabel, SidebarItemDateExtra } from './Components/Sidebar/SidebarItem';
272
+
273
+ export type { ContentSwitcherProps } from './Components/ContentSwitcher/ContentSwitcher';
274
+ export { default as ContentSwitcher } from './Components/ContentSwitcher/ContentSwitcher';
275
+
276
+ export type { ContentSwitcherItemProps } from './Components/ContentSwitcher/ContentSwitcherItem';
277
+ export { default as ContentSwitcherItem } from './Components/ContentSwitcher/ContentSwitcherItem';
package/src/theme.ts CHANGED
@@ -33,6 +33,7 @@ import ProgressBar from './Components/ProgressBar/ProgressBar.theme';
33
33
  import Slider from './Components/Slider/Slider.theme';
34
34
  import Sidebar from './Components/Sidebar/Sidebar.theme';
35
35
  import SidebarItem from './Components/Sidebar/SidebarItem.theme';
36
+ import ContentSwitcher from './Components/ContentSwitcher/ContentSwitcher.theme';
36
37
 
37
38
  import breakpoints from './Foundations/Breakpoints/Breakpoints';
38
39
  import colors from './Foundations/Colors/Colors';
@@ -113,6 +114,7 @@ const theme = {
113
114
  SidebarItem,
114
115
  Progress: ProgressBar,
115
116
  Slider,
117
+ ContentSwitcher,
116
118
  },
117
119
  };
118
120