@bitrise/bitkit 12.8.0 → 12.9.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.8.0",
4
+ "version": "12.9.0",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -23,6 +23,13 @@ const SidebarItemTheme = itemHelpers.defineMultiStyleConfig({
23
23
  },
24
24
  },
25
25
  variants: {
26
+ disabled: {
27
+ link: {
28
+ color: 'neutral.60',
29
+ _hover: { bg: 'unset' },
30
+ _active: { bg: 'unset' },
31
+ },
32
+ },
26
33
  selected: {
27
34
  link: {
28
35
  fontWeight: 'demiBold',
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import { forwardRef, ReactNode } from 'react';
2
2
  import { chakra, ChakraProps, createStylesContext, useMultiStyleConfig } from '@chakra-ui/react';
3
3
  import { DateTime } from 'luxon';
4
4
  import Text from '../Text/Text';
@@ -7,27 +7,42 @@ import Icon, { TypeIconName } from '../Icon/Icon';
7
7
  type SidebarItemProps = {
8
8
  children: ReactNode;
9
9
  selected?: boolean;
10
+ disabled?: boolean;
10
11
  onClick?: () => void;
11
12
  href?: string;
12
13
  };
13
14
 
14
15
  const [SidebarItemStyleProvider, useSidebarItemStyle] = createStylesContext('SidebarItem');
15
16
 
16
- const SidebarItem = ({ children, selected, href, onClick }: SidebarItemProps) => {
17
- const style = useMultiStyleConfig('SidebarItem', { variant: selected ? 'selected' : undefined });
18
- const shared = {
19
- onClick,
20
- position: 'relative',
21
- href,
22
- children: <SidebarItemStyleProvider value={style}>{children}</SidebarItemStyleProvider>,
23
- sx: style.link,
24
- height: '48',
25
- } as ChakraProps;
26
- if (onClick) {
27
- return <chakra.button {...shared} />;
17
+ const sidebarVariant = ({ selected, disabled }: { selected?: boolean; disabled?: boolean }) => {
18
+ if (disabled) {
19
+ return 'disabled';
28
20
  }
29
- return <chakra.a {...shared} />;
21
+ if (selected) {
22
+ return 'selected';
23
+ }
24
+ return undefined;
30
25
  };
26
+ const SidebarItem = forwardRef(
27
+ (
28
+ { children, disabled, selected, href, onClick }: SidebarItemProps,
29
+ ref: React.Ref<HTMLButtonElement & HTMLAnchorElement>,
30
+ ) => {
31
+ const style = useMultiStyleConfig('SidebarItem', { variant: sidebarVariant({ disabled, selected }) });
32
+ const shared = {
33
+ onClick,
34
+ position: 'relative',
35
+ href,
36
+ children: <SidebarItemStyleProvider value={style}>{children}</SidebarItemStyleProvider>,
37
+ sx: style.link,
38
+ height: '48',
39
+ } as ChakraProps;
40
+ if (onClick || disabled) {
41
+ return <chakra.button ref={ref} disabled={disabled} {...shared} />;
42
+ }
43
+ return <chakra.a ref={ref} {...shared} />;
44
+ },
45
+ );
31
46
 
32
47
  const SidebarItemIcon = ({ name }: { name: TypeIconName }) => {
33
48
  const { icon } = useSidebarItemStyle();