@takaro/lib-components 0.0.10 → 0.0.11

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@takaro/lib-components",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "private": false,
5
5
  "description": "Takaro UI is a simple and customizable component library to build React apps faster within the Takaro eco system",
6
6
  "license": "AGPL-3.0-or-later",
@@ -93,7 +93,19 @@ export function Table<DataType extends object>({
93
93
  if (column.id === undefined) {
94
94
  throw new Error('ColumnDef must have an id');
95
95
  }
96
- acc[column.id] = column?.meta?.hiddenColumn ? !column.meta.hiddenColumn : true;
96
+
97
+ if (column?.meta?.includeColumn == false) {
98
+ acc[column.id] = false;
99
+ return acc;
100
+ } else {
101
+ acc[column.id] = true;
102
+ }
103
+
104
+ if (column?.meta?.hideColumn) {
105
+ acc[column.id] = !column.meta.hideColumn;
106
+ } else {
107
+ acc[column.id] = true;
108
+ }
97
109
  return acc;
98
110
  },
99
111
  {} as Record<string, boolean>,
@@ -5,7 +5,10 @@ type DataTypes = 'datetime' | 'number' | 'string' | 'boolean' | 'uuid';
5
5
 
6
6
  declare module '@tanstack/table-core' {
7
7
  interface ColumnMeta<TData extends RowData, TValue> {
8
- hiddenColumn?: boolean;
8
+ /// Column is not visible in table by default, but can be enabled with view options
9
+ hideColumn?: boolean;
10
+ canShowColumn?: boolean;
11
+ includeColumn?: boolean;
9
12
  dataType?: DataTypes;
10
13
  }
11
14
  }
@@ -18,7 +18,16 @@ export function ColumnVisibility<DataType extends object>({
18
18
  openColumnVisibilityTooltip,
19
19
  setHasShownColumnVisibilityTooltip,
20
20
  }: ColumnVisibilityProps<DataType>) {
21
- const viableColumns = table.getAllLeafColumns().filter((column) => column.getCanHide() === true);
21
+ const viableColumns = table
22
+ .getAllLeafColumns()
23
+ .filter((column) => column.getCanHide() === true)
24
+ .filter((column) => {
25
+ if (column.columnDef.meta?.includeColumn === false) {
26
+ return false;
27
+ }
28
+ return true;
29
+ });
30
+
22
31
  const hiddenColumns = viableColumns.filter((column) => column.getIsVisible() === false);
23
32
 
24
33
  return (
@@ -1,4 +1,4 @@
1
- import { forwardRef, MouseEvent, useState } from 'react';
1
+ import { forwardRef, isValidElement, MouseEvent, ReactElement, useState } from 'react';
2
2
  import { Container, Grid, IconContainer, ButtonContainer } from './style';
3
3
  import {
4
4
  AiFillCheckCircle as Success,
@@ -20,14 +20,15 @@ type Action = {
20
20
  export interface AlertProps {
21
21
  variant: AlertVariants;
22
22
  title?: string;
23
- text?: string | string[];
23
+ text?: string | string[] | ReactElement;
24
24
  elevation?: Elevation;
25
25
  dismiss?: boolean;
26
26
  action?: Action;
27
+ showIcon?: boolean;
27
28
  }
28
29
 
29
30
  export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
30
- { variant, title, text, dismiss = false, elevation = 4, action },
31
+ { variant, title, text, dismiss = false, elevation = 4, action, showIcon = true },
31
32
  ref,
32
33
  ) {
33
34
  const [visible, setVisible] = useState(true);
@@ -39,7 +40,6 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
39
40
  e.stopPropagation();
40
41
  action?.execute();
41
42
  };
42
-
43
43
  const handleDismiss = (e: MouseEvent<HTMLButtonElement>) => {
44
44
  e.preventDefault();
45
45
  e.stopPropagation();
@@ -58,6 +58,19 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
58
58
  return <Info size={24} />;
59
59
  }
60
60
  }
61
+
62
+ function renderText() {
63
+ if (isValidElement(text)) {
64
+ return text;
65
+ }
66
+
67
+ if (typeof text === 'string') {
68
+ return <p>{text}</p>;
69
+ } else if (Array.isArray(text)) {
70
+ return <ul>{text?.map((message) => <li key={'message-' + message}>{message}</li>)}</ul>;
71
+ }
72
+ }
73
+
61
74
  return (
62
75
  <AnimatePresence>
63
76
  {visible && (
@@ -72,8 +85,8 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
72
85
  ref={ref}
73
86
  role="status"
74
87
  >
75
- <Grid hasTitle={hasTitle}>
76
- <IconContainer variant={variant}>{getIcon()}</IconContainer>
88
+ <Grid hasTitle={hasTitle} showIcon={showIcon}>
89
+ {showIcon && <IconContainer variant={variant}>{getIcon()}</IconContainer>}
77
90
 
78
91
  {/* If title is declared set title, otherwise put everything on single line */}
79
92
  {title && (
@@ -82,25 +95,13 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
82
95
  <div />
83
96
  </>
84
97
  )}
85
- {typeof text === 'string' ? (
86
- <p>{text}</p>
87
- ) : (
88
- text && (
89
- <ul>
90
- {text.map((message) => (
91
- <li key={'message-' + message}>{message}</li>
92
- ))}
93
- </ul>
94
- )
95
- )}
98
+ {renderText()}
96
99
  {hasTitle ? <div /> : null}
97
100
  <ButtonContainer hasTitle={hasTitle} show={dismiss || action ? true : false} variant={variant}>
98
101
  {action && (
99
- <Button size="small" variant="outline" onClick={handleExecute} text={action.text} color={variant} />
100
- )}
101
- {dismiss && (
102
- <Button size="small" color="white" variant="outline" onClick={handleDismiss} text="Dismiss" />
102
+ <Button size="tiny" variant="outline" onClick={handleExecute} text={action.text} color={variant} />
103
103
  )}
104
+ {dismiss && <Button size="tiny" color="white" variant="outline" onClick={handleDismiss} text="Dismiss" />}
104
105
  </ButtonContainer>
105
106
  </Grid>
106
107
  </Container>
@@ -58,10 +58,15 @@ export const Container = styled(motion.div)<{
58
58
  }}
59
59
  `;
60
60
 
61
- export const Grid = styled.div<{ hasTitle: boolean }>`
61
+ export const Grid = styled.div<{ hasTitle: boolean; showIcon: boolean }>`
62
62
  display: grid;
63
- grid-template-columns: ${({ theme, hasTitle }) =>
64
- !hasTitle ? `${theme.spacing[5]} 1fr fit-content(100px)` : `${theme.spacing[5]} 1fr`};}
63
+ grid-template-columns: ${({ theme, hasTitle, showIcon }) => {
64
+ const result = '';
65
+ if (showIcon) result.concat(`${theme.spacing[5]}`);
66
+ result.concat(' 1fr');
67
+ if (hasTitle) result.concat(' fit-content(100px)');
68
+ return result;
69
+ }}
65
70
  align-items: center;
66
71
  gap: ${({ theme, hasTitle }) => (hasTitle ? 0 : theme.spacing['0_5'])};
67
72
  `;
@@ -83,5 +88,6 @@ export const ButtonContainer = styled.div<{
83
88
  }>`
84
89
  display: ${({ show }): string => (show ? 'flex' : 'none')};
85
90
  align-items: center;
91
+ white-space: nowrap;
86
92
  margin-top: ${({ theme, hasTitle }): string => (hasTitle ? theme.spacing['1'] : theme.spacing[0])};
87
93
  `;
@@ -6,6 +6,13 @@ const Container = styled.div`
6
6
  margin-bottom: ${({ theme }) => theme.spacing['1']};
7
7
  hyphens: auto;
8
8
 
9
+ border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
10
+ padding: 10px 5px 0px 5px;
11
+ border-top-left-radius: 0;
12
+ border-top-right-radius: 0;
13
+ border-bottom-left-radius: 5px;
14
+ border-bottom-right-radius: 5px;
15
+
9
16
  p {
10
17
  hypens: auto;
11
18
  }
@@ -22,6 +22,18 @@ const Container = styled.button<{ open: boolean }>`
22
22
  margin-bottom: ${({ theme, open }) => (!open ? theme.spacing['1'] : theme.spacing['0_5'])};
23
23
  border: 1px solid ${({ theme }) => theme.colors.backgroundAccent};
24
24
  color: ${({ theme }) => theme.colors.textAlt};
25
+ font-size: ${({ theme }) => theme.fontSize.mediumLarge};
26
+
27
+ ${({ open }) => {
28
+ if (open) {
29
+ return `
30
+ border-bottom: 0;
31
+ border-bottom-left-radius: 0;
32
+ border-bottom-right-radius: 0;
33
+ margin-bottom: 0;
34
+ `;
35
+ }
36
+ }}
25
37
 
26
38
  svg {
27
39
  fill: ${({ theme }) => theme.colors.textAlt};