@bitrise/bitkit 10.3.0 → 10.4.0-alpha-ribbon.1

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": "10.3.0",
4
+ "version": "10.4.0-alpha-ribbon.1",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -1,8 +1,9 @@
1
1
  import { Button as ChakraButton, ButtonProps as ChakraButtonProps, forwardRef, useStyleConfig } from '@chakra-ui/react';
2
+ import { ColorScheme } from '@/Foundations/Colors/Colors';
2
3
 
3
4
  export interface ColorButtonProps extends ChakraButtonProps {
4
5
  as?: 'a' | 'button';
5
- colorScheme?: 'blue' | 'red' | 'green' | 'yellow' | 'purple';
6
+ colorScheme?: ColorScheme;
6
7
  }
7
8
 
8
9
  /**
@@ -10,7 +10,6 @@ export default {
10
10
  description: { type: 'string', defaultValue: 'description' },
11
11
  action: {
12
12
  control: 'inline-radio',
13
- defaultValue: 'unset',
14
13
  options: ['unset', 'link', 'action'],
15
14
  mapping: {
16
15
  unset: undefined,
@@ -38,3 +37,6 @@ export const Default: ComponentStoryFn<typeof Notification> = ({ title, descript
38
37
  <NotificationText>{description}</NotificationText>
39
38
  </Notification>
40
39
  );
40
+ Default.args = {
41
+ action: undefined,
42
+ };
@@ -1,4 +1,4 @@
1
- import { createContext, useContext, useMemo } from 'react';
1
+ import { createContext, ReactNode, useContext, useMemo } from 'react';
2
2
  import {
3
3
  Alert as ChakraAlert,
4
4
  AlertTitle as NotificationTitle,
@@ -9,12 +9,13 @@ import {
9
9
  chakra,
10
10
  } from '@chakra-ui/react';
11
11
 
12
+ import { ColorScheme } from '@/Foundations/Colors/Colors';
12
13
  import Box from '../Box/Box';
13
14
  import CloseButton from '../CloseButton/CloseButton';
14
15
  import ColorButton, { ColorButtonProps } from '../ColorButton/ColorButton';
15
16
  import Icon from '../Icon/Icon';
16
17
 
17
- const STATUSES = {
18
+ const STATUSES: Record<string, { colorScheme: ColorScheme; icon: ReactNode }> = {
18
19
  info: { colorScheme: 'blue', icon: <Icon flexShrink={0} name="Info" /> },
19
20
  error: { colorScheme: 'red', icon: <Icon flexShrink={0} name="ErrorGeneral" /> },
20
21
  success: { colorScheme: 'green', icon: <Icon flexShrink={0} name="Tick" /> },
@@ -39,14 +40,14 @@ export interface NotificationProps extends Omit<AlertProps, 'status' | 'colorSch
39
40
  action?: ActionProps;
40
41
  }
41
42
 
42
- const ActionContext = createContext<{ colorScheme: ColorButtonProps['colorScheme'] }>({ colorScheme: 'blue' });
43
+ const ActionContext = createContext<{ colorScheme: ColorScheme }>({ colorScheme: 'blue' });
43
44
 
44
45
  const NotificationAction = ({ label, href, ...rest }: ActionProps) => {
45
46
  const actionContext = useContext(ActionContext);
46
47
  return (
47
48
  <ColorButton
48
49
  flexGrow={0}
49
- flexShrink={1}
50
+ flexShrink={0}
50
51
  as={(href ? 'a' : 'button') as any}
51
52
  href={href}
52
53
  {...actionContext}
@@ -0,0 +1,35 @@
1
+ import { ComponentMeta, ComponentStoryFn } from '@storybook/react';
2
+ import { action } from '@storybook/addon-actions';
3
+ import Ribbon from './Ribbon';
4
+
5
+ export default {
6
+ title: 'Components/Ribbon',
7
+ component: Ribbon,
8
+ argTypes: {
9
+ children: { type: 'string' },
10
+ action: {
11
+ control: 'inline-radio',
12
+ options: ['unset', 'link', 'action'],
13
+ mapping: {
14
+ unset: undefined,
15
+ link: { label: 'link', href: '#' },
16
+ action: { label: 'action', onClick: action('action') },
17
+ },
18
+ },
19
+ onClose: {
20
+ control: 'inline-radio',
21
+ options: ['unset', 'action'],
22
+ mapping: {
23
+ unset: undefined,
24
+ action: action('onClose'),
25
+ },
26
+ },
27
+ },
28
+ args: {
29
+ children: 'text',
30
+ colorScheme: 'blue',
31
+ action: undefined,
32
+ },
33
+ } as ComponentMeta<typeof Ribbon>;
34
+
35
+ export const Default: ComponentStoryFn<typeof Ribbon> = (args) => <Ribbon {...args} />;
@@ -0,0 +1,77 @@
1
+ import { createContext, useContext, useMemo } from 'react';
2
+ import { Alert as ChakraAlert, AlertProps, forwardRef } from '@chakra-ui/react';
3
+
4
+ import { ColorScheme } from '@/Foundations/Colors/Colors';
5
+ import CloseButton from '../CloseButton/CloseButton';
6
+ import ColorButton, { ColorButtonProps } from '../ColorButton/ColorButton';
7
+ import Icon from '../Icon/Icon';
8
+ import Box from '../Box/Box';
9
+
10
+ export type ActionProps = {
11
+ label: string;
12
+ href?: string;
13
+ onClick?: () => void;
14
+ } & Omit<ColorButtonProps, 'as' | 'onClick' | 'colorScheme'>;
15
+
16
+ export interface RibbonProps extends Omit<AlertProps, 'status' | 'colorScheme' | 'onClose'> {
17
+ colorScheme: ColorScheme;
18
+ onClose?: () => void;
19
+ action?: ActionProps;
20
+ }
21
+
22
+ const ActionContext = createContext<{
23
+ colorScheme: ColorButtonProps['colorScheme'];
24
+ }>({ colorScheme: 'blue' });
25
+
26
+ const RibbonAction = ({ label, href, ...rest }: ActionProps) => {
27
+ const actionContext = useContext(ActionContext);
28
+ return (
29
+ <ColorButton
30
+ flexGrow={0}
31
+ flexShrink={0}
32
+ as={(href ? 'a' : 'button') as any}
33
+ marginY={-4}
34
+ href={href}
35
+ {...actionContext}
36
+ {...rest}
37
+ >
38
+ {label}
39
+ </ColorButton>
40
+ );
41
+ };
42
+
43
+ const Ribbon = forwardRef<RibbonProps, 'div'>((props, ref) => {
44
+ const { action, children, onClose, colorScheme, ...rest } = props;
45
+ const actionContext = useMemo(() => ({ colorScheme }), [colorScheme]);
46
+ let actionButton;
47
+ if (action) {
48
+ actionButton = <RibbonAction {...action} />;
49
+ }
50
+
51
+ return (
52
+ <ChakraAlert
53
+ ref={ref}
54
+ colorScheme={colorScheme}
55
+ justifyContent="center"
56
+ alignItems="center"
57
+ gap={16}
58
+ borderRadius={0}
59
+ borderLeftWidth={0}
60
+ borderRightWidth={0}
61
+ {...rest}
62
+ >
63
+ <ActionContext.Provider value={actionContext}>
64
+ {onClose && <Box width={24} height={24} marginRight="auto" />}
65
+ {children}
66
+ {actionButton}
67
+ {onClose && (
68
+ <CloseButton flexShrink={0} colorScheme={colorScheme} marginStart="auto" onClick={onClose}>
69
+ <Icon name="CloseSmall" />
70
+ </CloseButton>
71
+ )}
72
+ </ActionContext.Provider>
73
+ </ChakraAlert>
74
+ );
75
+ });
76
+
77
+ export default Ribbon;
@@ -126,4 +126,7 @@ const colors = {
126
126
  };
127
127
 
128
128
  export type Colors = typeof colors;
129
+
130
+ export type ColorScheme = 'blue' | 'red' | 'green' | 'yellow' | 'purple';
131
+
129
132
  export default colors;
@@ -1,6 +1,8 @@
1
+ import { ColorScheme } from '../Colors/Colors';
2
+
1
3
  const AlertTheme = {
2
4
  parts: ['container', 'title', 'icon', 'body'],
3
- baseStyle({ colorScheme }: { colorScheme: 'blue' | 'red' | 'green' | 'yellow' | 'purple' }) {
5
+ baseStyle({ colorScheme }: { colorScheme: ColorScheme }) {
4
6
  return {
5
7
  container: {
6
8
  display: 'flex',
package/src/index.ts CHANGED
@@ -136,4 +136,7 @@ export { default as Breadcrumb } from './Components/Breadcrumb/Breadcrumb';
136
136
  export type { BreadcrumbLinkProps } from './Components/Breadcrumb/BreadcrumbLink';
137
137
  export { default as BreadcrumbLink } from './Components/Breadcrumb/BreadcrumbLink';
138
138
 
139
+ export type { RibbonProps } from './Components/Ribbon/Ribbon';
140
+ export { default as Ribbon } from './Components/Ribbon/Ribbon';
141
+
139
142
  export { BREAKPOINTS } from './Foundations/Breakpoints/Breakpoints';
package/src/old.ts CHANGED
@@ -66,9 +66,6 @@ export { default as ProgressBitbot } from './Old/Progress/ProgressBitbot';
66
66
  export type { Props as ProgressSpinnerProps } from './Old/Progress/ProgressSpinner';
67
67
  export { default as ProgressSpinner } from './Old/Progress/ProgressSpinner';
68
68
 
69
- export type { Props as RibbonProps } from './Old/Ribbon/Ribbon';
70
- export { default as Ribbon } from './Old/Ribbon/Ribbon';
71
-
72
69
  export type { Props as SkeletonProps } from './Old/Skeleton/Skeleton';
73
70
  export { default as Skeleton } from './Old/Skeleton/Skeleton';
74
71
 
package/src/theme.ts CHANGED
@@ -15,7 +15,7 @@ import Radio from './Components/Form/Radio/Radio.theme';
15
15
  import Select from './Components/Select/Select.theme';
16
16
  import Tabs from './Components/Tabs/Tabs.theme';
17
17
  import Text from './Components/Text/Text.theme';
18
- import Notification from './Components/Notification/Notification.theme';
18
+ import Alert from './Foundations/Themes/Alert.theme';
19
19
  import Tooltip from './Components/Tooltip/Tooltip.theme';
20
20
  import CloseButton from './Components/CloseButton/CloseButton.theme';
21
21
  import Popover from './Components/Popover/Popover.theme';
@@ -82,7 +82,7 @@ const theme = {
82
82
  Tabs,
83
83
  Text,
84
84
  Tooltip,
85
- Alert: Notification,
85
+ Alert,
86
86
  CloseButton,
87
87
  Popover,
88
88
  },