@bolttech/atoms-segmented-control 0.9.0 → 0.10.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/README.md CHANGED
@@ -1,8 +1,98 @@
1
- # atoms-segmented-control
1
+ # SegmentedControl Component
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ The **SegmentedControl** component is a React component designed to provide a segmented control input for selecting options. This component allows users to choose from a set of options using a visually distinct set of buttons.
4
4
 
5
- ## Running unit tests
5
+ ## Table of Contents
6
6
 
7
+ - [Installation](#installation)
8
+ - [Usage](#usage)
9
+ - [Props](#props)
10
+ - [Example](#example)
11
+ - [Contributing](#contributing)
7
12
 
8
- Run `nx test atoms-segmented-control` to execute the unit tests via [Jest](https://jestjs.io).
13
+ ## Installation
14
+
15
+ To use the **SegmentedControl** component in your React application, follow these steps:
16
+
17
+ ### Installation
18
+
19
+ ```bash
20
+ npm install @edirect/frontend-foundations @bolttech/atoms-segmented-control
21
+ ```
22
+
23
+ or
24
+
25
+ ```bash
26
+ yarn add @edirect/frontend-foundations @bolttech/atoms-segmented-control
27
+ ```
28
+
29
+ Once you have the required dependencies installed, you can start using the `SegmentedControl` component in your React application.
30
+
31
+ ## Usage
32
+
33
+ The **SegmentedControl** component provides a set of visually distinct buttons that allow users to select from a predefined set of options. It supports customization through various props.
34
+
35
+ To use the component, import it and include it in your JSX:
36
+
37
+ ```jsx
38
+ import React from 'react';
39
+ import {SegmentedControl} from '@bolttech/atoms-segmented-control';
40
+ import {bolttechTheme, BolttechThemeProvider} from "@edirect/frontend-foundations";
41
+
42
+ function App() {
43
+ return (
44
+ <BolttechThemeProvider theme={bolttechTheme}>
45
+ <SegmentedControl
46
+ value="option1"
47
+ options={[
48
+ {label: 'Option 1', value: 'option1'},
49
+ {label: 'Option 2', value: 'option2'},
50
+ ]}
51
+ errorMessage="An error occurred"
52
+ dataTestId="segmented-control-component"
53
+ onChange={(selectedValue) => console.log(`Selected: ${selectedValue}`)}
54
+ />
55
+ </BolttechThemeProvider>
56
+ );
57
+ }
58
+
59
+ export default App;
60
+ ```
61
+
62
+ ## Props
63
+
64
+ The **SegmentedControl** component accepts the following props:
65
+
66
+ | Prop | Type | Description |
67
+ |--------------|---------------|---------------------------------------------------|
68
+ | `id` | string | The HTML `id` attribute for the segmented control.|
69
+ | `dataTestId` | string | The data-testid attribute for testing purposes. |
70
+ | `value` | string | The currently selected option value. |
71
+ | `options` | Option[] | An array of option objects to be displayed. |
72
+ | `errorMessage` | string | An optional error message to display. |
73
+ | `onChange` | function | A callback function triggered on option change. |
74
+ | `onBlur` | function | A callback function triggered on blur event. |
75
+ | `onFocus` | function | A callback function triggered on focus event. |
76
+
77
+ ## Example
78
+
79
+ Here's an example of using the **SegmentedControl** component:
80
+
81
+ ```jsx
82
+ <SegmentedControl
83
+ value="option1"
84
+ options={[
85
+ { label: 'Option 1', value: 'option1' },
86
+ { label: 'Option 2', value: 'option2' },
87
+ ]}
88
+ errorMessage="An error occurred"
89
+ dataTestId="segmented-control-component"
90
+ onChange={(selectedValue) => console.log(`Selected: ${selectedValue}`)}
91
+ />
92
+ ```
93
+
94
+ This will render a **SegmentedControl** component with two options, the first option selected, and an error message displayed.
95
+
96
+ ## Contributing
97
+
98
+ Contributions to the **SegmentedControl** component are welcome. If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the project's Bitbucket repository.
package/index.cjs CHANGED
@@ -4,6 +4,7 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
+ var react = require('react');
7
8
  var styled = require('styled-components');
8
9
 
9
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -84,16 +85,16 @@ const LabelError = /*#__PURE__*/styled__default["default"].label.withConfig({
84
85
  theme
85
86
  }) => theme.typography.desktop.input.secondary.textCase);
86
87
 
87
- function SegmentedControl({
88
- id = 'segmented-control-id',
89
- dataTestId = 'segmented-control-date-testid',
88
+ const SegmentedControl = /*#__PURE__*/react.forwardRef(({
89
+ id: _id = 'segmented-control-id',
90
+ dataTestId: _dataTestId = 'segmented-control-date-testid',
90
91
  value,
91
92
  options,
92
93
  errorMessage,
93
94
  onChange,
94
95
  onBlur,
95
96
  onFocus
96
- }) {
97
+ }, ref) => {
97
98
  const onClick = valueSelected => {
98
99
  onChange && onChange(valueSelected);
99
100
  };
@@ -114,17 +115,18 @@ function SegmentedControl({
114
115
  }, `segmentedcontrol-option-${option.value}`));
115
116
  };
116
117
  return jsxRuntime.jsxs(SegmentedControlContainer, {
117
- id: id,
118
- "data-testid": dataTestId,
118
+ id: _id,
119
+ "data-testid": _dataTestId,
120
+ ref: ref,
119
121
  children: [jsxRuntime.jsx(SegmentedControlWrapper, {
120
122
  onBlur: onBlur,
121
123
  onFocus: onFocus,
122
124
  children: renderOptions()
123
125
  }), errorMessage && jsxRuntime.jsx(LabelError, {
124
- "data-testid": `${dataTestId}-error`,
126
+ "data-testid": `${_dataTestId}-error`,
125
127
  children: errorMessage
126
128
  })]
127
129
  });
128
- }
130
+ });
129
131
 
130
132
  exports.SegmentedControl = SegmentedControl;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@bolttech/atoms-segmented-control",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "main": "./index.cjs",
5
5
  "type": "commonjs",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {
8
- "@edirect/frontend-foundations": "0.0.58",
8
+ "@edirect/frontend-foundations": "0.0.67",
9
9
  "react": "18.2.0",
10
10
  "styled-components": "5.3.6"
11
11
  },
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { SegmentedControlProps } from './atoms-segmented-control.type';
2
- export declare function SegmentedControl({ id, dataTestId, value, options, errorMessage, onChange, onBlur, onFocus, }: SegmentedControlProps): import("react/jsx-runtime").JSX.Element;
3
+ export declare const SegmentedControl: import("react").ForwardRefExoticComponent<SegmentedControlProps & import("react").RefAttributes<HTMLDivElement>>;
3
4
  export default SegmentedControl;