@oliasoft-open-source/react-ui-library 4.20.10 → 4.20.11-beta-2

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
@@ -142,6 +142,7 @@ To quickly start a new project using the React UI Library with Vite, you can use
142
142
  - [Tree](#tree)
143
143
  - [NumberInput](#numberinput)
144
144
  - [UnitInput](#unitinput)
145
+ - [UnitTable](#unittable)
145
146
 
146
147
  ## Storybook
147
148
 
@@ -2062,6 +2063,60 @@ The `Table` component renders tabular data with various customization options.
2062
2063
 
2063
2064
  <hr style="border: none; border-right: 2px solid black; width: 100%; height: 1px;">
2064
2065
 
2066
+ ## UnitTable Component <a id="unittable"></a>
2067
+
2068
+ The `UnitTable` component is a wrapper around `Table`, with local state and additional logic to handle displaying tables in preferred units, and converting return values when cells are edited.
2069
+
2070
+ ### Props
2071
+
2072
+ | Prop | Description | Default Value |
2073
+ |--------------------------|------------------------------------------------------------------------------------------------------------------------|---------------|
2074
+ | `table` | An object containing table configuration, similar to `ITableTableProps`. | |
2075
+ | `unitConfig` | Array of unit configuration objects, each with `unitKey`, `storageUnit`, optional `preferredUnit`, and `onChange` callback. See [unitConfig item structure](#unitconfig-item-structure). | |
2076
+ | `convertBackToStorageUnit` | Whether values should be converted back to the storage unit when edited. | `true` |
2077
+ | `enableCosmeticRounding` | Enables cosmetic rounding of displayed values (Excel-style) to reduce visual precision noise. | `true` |
2078
+ | `enableDisplayRounding` | Enables rounding of displayed values in number inputs until the cell is focused. | `true` |
2079
+ | `onListReorder` | Function called when rows are reordered via drag-and-drop. Receives `{ from: number; to: number }` as an argument. | `() => {}` |
2080
+ | `canListReorder` | Function to determine whether a row can be reordered. Receives `{ from: number; to: number }` as an argument and returns `boolean`. | `() => true` |
2081
+
2082
+ ---
2083
+
2084
+ ### `unitConfig` Item Structure
2085
+
2086
+ Each object in the `unitConfig` array should have the following shape:
2087
+
2088
+ | Key | Type | Description |
2089
+ |------------------|---------------------------------------|------------------------------------------------------------------------------------------------------------------------|
2090
+ | `unitKey` | `string` | Key representing the type of unit (e.g., `length`, `temperature`, `density`). |
2091
+ | `storageUnit` | `string` | The unit in which data is stored internally (e.g., `m`, `ft`, `C`, `sg`). |
2092
+ | `preferredUnit` | `string` _(optional)_ | The user's preferred display unit (e.g., `ft`, `F`, `ppg`). |
2093
+ | `onChange` | `(params: { oldUnit: string; newUnit: string; unitKey: string }) => void` _(optional)_ | Callback when the display unit is changed by the user. |
2094
+
2095
+ ---
2096
+
2097
+ ### Usage Example
2098
+
2099
+ ```jsx
2100
+ <UnitTable
2101
+ table={{
2102
+ draggable: true,
2103
+ headers: [...],
2104
+ rows: [...],
2105
+ }}
2106
+ unitConfig={[
2107
+ {
2108
+ unitKey: 'length',
2109
+ storageUnit: 'm',
2110
+ preferredUnit: 'ft',
2111
+ onChange: ({ oldUnit, newUnit, unitKey }) =>
2112
+ console.log(`Unit changed for ${unitKey} from ${oldUnit} to ${newUnit}`),
2113
+ },
2114
+ ]}
2115
+ onListReorder={({ from, to }) => console.log(`Moved row from ${from} to ${to}`)}
2116
+ canListReorder={({ from, to }) => from !== to}
2117
+ />
2118
+ ```
2119
+
2065
2120
  ## Tabs Component <a id="tabs"></a>
2066
2121
 
2067
2122
  The `Tabs` component creates a tabbed interface for organizing content.
package/dist/index.d.ts CHANGED
@@ -1652,6 +1652,14 @@ export declare interface IUnitTableProps extends Omit<ITableProps, 'table'> {
1652
1652
  convertBackToStorageUnit?: boolean;
1653
1653
  enableCosmeticRounding?: boolean;
1654
1654
  enableDisplayRounding?: boolean;
1655
+ onListReorder?: (obj: {
1656
+ from: number;
1657
+ to: number;
1658
+ }) => void;
1659
+ canListReorder?: (obj: {
1660
+ from: number;
1661
+ to: number;
1662
+ }) => boolean;
1655
1663
  }
1656
1664
 
1657
1665
  export declare interface IUnitTableRow extends Omit<TRowType, 'cells'> {
@@ -1919,7 +1927,7 @@ declare type UnitContextType = any;
1919
1927
 
1920
1928
  export declare const UnitInput: ({ name, placeholder, disabled, disabledUnit, error, left, small, width, value, unitkey, initUnit, noConversion, onChange, onClick, onFocus, onSwitchUnit, unitTemplate, testId, warning, predefinedOptions, initialPredefinedOption, shouldLinkAutomaticly, selectedPredefinedOptionKey, validationCallback, disabledValidation, allowEmpty, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, roundDisplayValue, selectOnFocus, groupOrder, }: IUnitInputProps) => JSX_2.Element;
1921
1929
 
1922
- export declare const UnitTable: ({ table, unitConfig, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, }: IUnitTableProps) => JSX_2.Element;
1930
+ export declare const UnitTable: ({ table, unitConfig, convertBackToStorageUnit, enableCosmeticRounding, enableDisplayRounding, onListReorder, canListReorder, }: IUnitTableProps) => JSX_2.Element;
1923
1931
 
1924
1932
  export declare const useFocus: () => UseFocusReturnType;
1925
1933
 
package/dist/index.js CHANGED
@@ -66704,7 +66704,9 @@ const UnitTable = ({
66704
66704
  unitConfig,
66705
66705
  convertBackToStorageUnit = true,
66706
66706
  enableCosmeticRounding = true,
66707
- enableDisplayRounding = true
66707
+ enableDisplayRounding = true,
66708
+ onListReorder,
66709
+ canListReorder
66708
66710
  }) => {
66709
66711
  const { rows, headers, ...otherProps } = table2;
66710
66712
  const { storageUnits, preferredUnits } = normalizeUnits(unitConfig);
@@ -66764,7 +66766,9 @@ const UnitTable = ({
66764
66766
  ...otherProps,
66765
66767
  headers: viewData.convertedHeaders,
66766
66768
  rows: viewData.convertedRows
66767
- }
66769
+ },
66770
+ onListReorder,
66771
+ canListReorder
66768
66772
  }
66769
66773
  );
66770
66774
  };