@takaro/lib-components 0.0.24 → 0.0.25

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.24",
3
+ "version": "0.0.25",
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",
@@ -3,6 +3,6 @@ import { expect, it } from 'vitest';
3
3
  import { render } from '../../../test/testUtils';
4
4
 
5
5
  it('Should render <Button/>', () => {
6
- const { container } = render(<Button text="button text" />);
6
+ const { container } = render(<Button>button text</Button>);
7
7
  expect(container).toMatchSnapshot();
8
8
  });
@@ -1,4 +1,4 @@
1
- import { JSX, cloneElement, forwardRef, MouseEvent as ReactMouseEvent, ReactElement } from 'react';
1
+ import { JSX, cloneElement, forwardRef, MouseEvent as ReactMouseEvent, ReactElement, PropsWithChildren } from 'react';
2
2
  import { Spinner } from '../../../components';
3
3
  import { ButtonColor, Default, Outline, Clear, White } from './style';
4
4
  import { Size, Variant } from '../../../styled';
@@ -16,13 +16,11 @@ export interface ButtonProps {
16
16
  // TODO: clear should be renamed to text
17
17
  variant?: Variant | 'white' | 'clear';
18
18
  color?: ButtonColor | 'white';
19
- text: string;
20
-
21
19
  /// When nesting forms a button can be linked to only fire the form with the given name.
22
20
  form?: string;
23
21
  }
24
22
 
25
- export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
23
+ export const Button = forwardRef<HTMLButtonElement, PropsWithChildren<ButtonProps>>(function Button(
26
24
  {
27
25
  icon,
28
26
  iconPosition = 'left',
@@ -30,8 +28,8 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
30
28
  type = 'button',
31
29
  isLoading = false,
32
30
  className,
31
+ children,
33
32
  form,
34
- text,
35
33
  color = 'primary',
36
34
  disabled = false,
37
35
  fullWidth = false,
@@ -69,25 +67,25 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
69
67
  case 'default':
70
68
  return (
71
69
  <Default {...props}>
72
- {iconPosition === 'left' && getIcon()} <span>{text}</span> {iconPosition === 'right' && getIcon()}
70
+ {iconPosition === 'left' && getIcon()} <span>{children}</span> {iconPosition === 'right' && getIcon()}
73
71
  </Default>
74
72
  );
75
73
  case 'outline':
76
74
  return (
77
75
  <Outline {...props}>
78
- {iconPosition === 'left' && getIcon()} <span>{text}</span> {iconPosition === 'right' && getIcon()}
76
+ {iconPosition === 'left' && getIcon()} <span>{children}</span> {iconPosition === 'right' && getIcon()}
79
77
  </Outline>
80
78
  );
81
79
  case 'clear':
82
80
  return (
83
81
  <Clear {...props}>
84
- {iconPosition === 'left' && getIcon()} <span>{text}</span> {iconPosition === 'right' && getIcon()}
82
+ {iconPosition === 'left' && getIcon()} <span>{children}</span> {iconPosition === 'right' && getIcon()}
85
83
  </Clear>
86
84
  );
87
85
  case 'white':
88
86
  return (
89
87
  <White {...props}>
90
- {iconPosition === 'left' && getIcon()} <span>{text}</span> {iconPosition === 'right' && getIcon()}
88
+ {iconPosition === 'left' && getIcon()} <span>{children}</span> {iconPosition === 'right' && getIcon()}
91
89
  </White>
92
90
  );
93
91
  }
@@ -40,7 +40,9 @@ export const ZoomControls: FC<ZoomControlsProps> = ({ zoom }) => {
40
40
  </Tooltip.Trigger>
41
41
  <Tooltip.Content>Zoom out</Tooltip.Content>
42
42
  </Tooltip>
43
- <Button size="tiny" onClick={zoom.reset} text="Reset" />
43
+ <Button size="tiny" onClick={zoom.reset}>
44
+ Reset
45
+ </Button>
44
46
  {/*<Button size="tiny" onClick={zoom.center} text="Center" />*/}
45
47
  </Controls>
46
48
  );
@@ -78,8 +78,12 @@ export const Console: FC<ConsoleProps> = ({ listenerFactory, onExecuteCommand, s
78
78
  return (
79
79
  <Wrapper>
80
80
  <Header>
81
- <Button onClick={() => setIsLiveModeEnabled(true)} text="Follow" disabled={isLiveModeEnabled} />
82
- <Button onClick={() => setMessages([])} text="Clear" color="background" icon={<ClearIcon />} />
81
+ <Button onClick={() => setIsLiveModeEnabled(true)} disabled={isLiveModeEnabled}>
82
+ Follow
83
+ </Button>
84
+ <Button onClick={() => setMessages([])} color="background" icon={<ClearIcon />}>
85
+ Clear
86
+ </Button>
83
87
  </Header>
84
88
  <MessageContainer>
85
89
  <Autosizer>
@@ -149,8 +149,12 @@ export const DrawerContent = forwardRef<HTMLElement, HTMLProps<HTMLDivElement>>(
149
149
  <h2>Your progress will be lost</h2>
150
150
  <p>Are you sure you want to exit? Your progress will not be saved.</p>
151
151
  <ButtonContainer>
152
- <Button text="Cancel" color="secondary" onClick={() => setShowConfirmDialog(false)} />
153
- <Button text="Discard changes" onClick={() => setOpen(false)} color="error" />
152
+ <Button color="secondary" onClick={() => setShowConfirmDialog(false)}>
153
+ Cancel
154
+ </Button>
155
+ <Button onClick={() => setOpen(false)} color="error">
156
+ Discard changes
157
+ </Button>
154
158
  </ButtonContainer>
155
159
  </CloseConfirmationContainer>
156
160
  </CloseConfirmationWrapper>
@@ -36,7 +36,9 @@ export const InfiniteScroll = forwardRef<HTMLElement, InfiniteScrollProps>(funct
36
36
  ref={ref}
37
37
  style={{ display: 'flex', height: '100%', width: '100%', justifyContent: 'center', alignItems: 'center' }}
38
38
  >
39
- <Button text="Load more" ref={ref} onClick={handleOnClick} />
39
+ <Button ref={ref} onClick={handleOnClick}>
40
+ Load more
41
+ </Button>
40
42
  </div>
41
43
  )}
42
44
  {hasNextPage && isFetchingNextPage && (
@@ -375,8 +375,9 @@ export function Table<DataType extends object>({
375
375
  key={id + '-learn-more-button'}
376
376
  variant="clear"
377
377
  onClick={() => window.open('https://docs.takaro.io')}
378
- text="Learn more"
379
- />,
378
+ >
379
+ Learn more
380
+ </Button>,
380
381
  ]}
381
382
  />
382
383
  </div>
@@ -195,7 +195,9 @@ export function Filter<DataType extends object>({ table }: FilterProps<DataType>
195
195
  })}
196
196
  <ButtonContainer justifyContent={fields.length > 0 ? 'space-between' : 'flex-end'}>
197
197
  {fields.length > 0 && (
198
- <Button type="button" variant="clear" text="Clear filters" onClick={handleClearFilters} />
198
+ <Button type="button" variant="clear" onClick={handleClearFilters}>
199
+ Clear filters
200
+ </Button>
199
201
  )}
200
202
  <FilterActions>
201
203
  <Button
@@ -208,9 +210,10 @@ export function Filter<DataType extends object>({ table }: FilterProps<DataType>
208
210
  })
209
211
  }
210
212
  variant="clear"
211
- text="Add filter"
212
- />
213
- <Button type="submit" text="Apply filters" />
213
+ >
214
+ Add filter
215
+ </Button>
216
+ <Button type="submit">Apply filters</Button>
214
217
  </FilterActions>
215
218
  </ButtonContainer>
216
219
  </form>
@@ -88,8 +88,9 @@ export const PagePicker: FC<PagePickerProps> = ({
88
88
  variant="outline"
89
89
  onClick={() => setPageIndex(i - 1)}
90
90
  className={i === pageIndex + 1 ? 'active' : ''}
91
- text={`${i}`}
92
- />
91
+ >
92
+ {i}
93
+ </Button>
93
94
  ))}
94
95
  {showButtons && (
95
96
  <IconButton size="tiny" icon={<NextIcon />} onClick={nextPage} disabled={!hasNext} ariaLabel="next page" />
@@ -95,9 +95,15 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
95
95
  className="action"
96
96
  >
97
97
  {action && (
98
- <Button size="tiny" variant="outline" onClick={handleExecute} text={action.text} color={variant} />
98
+ <Button size="tiny" variant="outline" onClick={handleExecute} color={variant}>
99
+ {action.text}
100
+ </Button>
101
+ )}
102
+ {dismiss && (
103
+ <Button size="tiny" color="white" variant="outline" onClick={handleDismiss}>
104
+ Dismiss
105
+ </Button>
99
106
  )}
100
- {dismiss && <Button size="tiny" color="white" variant="outline" onClick={handleDismiss} text="Dismiss" />}
101
107
  </ButtonContainer>
102
108
  </Grid>
103
109
  </Container>
@@ -98,8 +98,8 @@ export const CookieConsentSnack = forwardRef<HTMLDivElement, CustomContentProps>
98
98
  </strong>
99
99
  </div>
100
100
  <ButtonContainer>
101
- <Button text="Decline" />
102
- <Button text="Accept" type="submit" />
101
+ <Button>Decline</Button>
102
+ <Button type="submit">Accept</Button>
103
103
  </ButtonContainer>
104
104
  </Wrapper>
105
105
  );
@@ -262,16 +262,18 @@ export const GenericDatePicker: FC<GenericDatePickerProps> = ({
262
262
  fullWidth
263
263
  variant="default"
264
264
  color="secondary"
265
- text="Cancel"
266
- />
265
+ >
266
+ Cancel
267
+ </Button>
267
268
  <Button
268
269
  fullWidth
269
270
  onClick={() => {
270
271
  handleOnChange(selectedDateTime);
271
272
  setOpen(false);
272
273
  }}
273
- text="Select"
274
- />
274
+ >
275
+ Select
276
+ </Button>
275
277
  </ButtonContainer>
276
278
  )}
277
279
  </ContentContainer>
@@ -124,7 +124,7 @@ export const QuickSelect: FC<QuickSelectProps> = ({ id }) => {
124
124
  </SelectField.OptionGroup>
125
125
  </SelectField>
126
126
  </InputsContainer>
127
- <Button type="submit" text="Apply" />
127
+ <Button type="submit">Apply</Button>
128
128
  </StyledForm>
129
129
 
130
130
  <Divider fullWidth />
@@ -125,7 +125,7 @@ export const RelativePicker: FC<RelativePickerProps> = ({ onChange, id, timeDire
125
125
  </SelectField.OptionGroup>
126
126
  </SelectField>
127
127
  </InputsContainer>
128
- <Button type="submit" text="Apply" />
128
+ <Button type="submit">Apply</Button>
129
129
  </StyledForm>
130
130
 
131
131
  <Divider fullWidth />
@@ -181,12 +181,13 @@ export const GenericDurationField = forwardRef<HTMLDivElement, GenericDurationFi
181
181
  form={formId}
182
182
  type="submit"
183
183
  fullWidth
184
- text="Apply"
185
184
  onClick={(e) => {
186
185
  e.preventDefault();
187
186
  handleSubmit(onSubmit)();
188
187
  }}
189
- />
188
+ >
189
+ Apply
190
+ </Button>
190
191
  </ButtonContainer>
191
192
  </form>
192
193
  </InnerContent>
@@ -15,12 +15,11 @@ interface DescriptionProps {
15
15
  }
16
16
 
17
17
  export const Description: FC<DescriptionProps> = ({ description, inputName, style }) => {
18
- const urlPattern = /(https?:\/\/[^\s]+)/g;
19
-
18
+ const urlPattern = /(https?:\/\/[^\s)]+)/g;
20
19
  return (
21
20
  <StyledP id={`${inputName}-description`} style={style}>
22
21
  {description.split(urlPattern).map((part, i) => {
23
- if (part.match(urlPattern)) {
22
+ if (i % 2 === 1) {
24
23
  return (
25
24
  <a key={`${i}`} href={part} target="_blank" rel="noopener noreferrer" className="underline">
26
25
  {part}
@@ -81,7 +81,7 @@ export const Plan: FC<PlanProps> = ({
81
81
  </p>
82
82
  )}
83
83
  <a style={{ width: '100%' }} className="button" href={to} target="_blank" rel="noreferrer">
84
- <Button fullWidth text={buttonText} />
84
+ <Button fullWidth>{buttonText}</Button>
85
85
  </a>
86
86
  <p></p>
87
87
  </div>