@bodynarf/react.components 1.5.8 → 1.6.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.
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { ButtonWithIconProps } from "../../types";
2
3
  /** Button with icon component */
3
4
  export declare const ButtonWithIcon: ({ className, disabled, onClick, caption, title, icon, data, }: ButtonWithIconProps) => JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/button/components/buttonWithIcon/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,iCAAiC;AACjC,eAAO,MAAM,cAAc,kEAKxB,mBAAmB,KAAG,WAwCxB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/button/components/buttonWithIcon/index.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,iCAAiC;AACjC,eAAO,MAAM,cAAc,kEAKxB,mBAAmB,KAAG,WAwCxB,CAAC"}
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { SimpleButtonProps } from "../../types";
2
3
  /** Simple button component, without icon */
3
4
  export declare const SimpleButton: ({ className, disabled, onClick, caption, title, data }: SimpleButtonProps) => JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/button/components/simpleButton/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,4CAA4C;AAC5C,eAAO,MAAM,YAAY,2DAKtB,iBAAiB,KAAG,WAYtB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/button/components/simpleButton/index.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,4CAA4C;AAC5C,eAAO,MAAM,YAAY,2DAKtB,iBAAiB,KAAG,WAYtB,CAAC"}
@@ -7,4 +7,5 @@ export * from "./paginator";
7
7
  export * from "./primitives";
8
8
  export * from "./search";
9
9
  export * from "./tag";
10
+ export * from "./tabs";
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC"}
@@ -7,3 +7,4 @@ export * from "./paginator";
7
7
  export * from "./primitives";
8
8
  export * from "./search";
9
9
  export * from "./tag";
10
+ export * from "./tabs";
@@ -0,0 +1,33 @@
1
+ import "./style.scss";
2
+ import { BaseElementProps, ElementSize } from "../..";
3
+ import { TabItem, TabsPosition, TabsStyle } from "..";
4
+ /** Tabs component props type */
5
+ export interface TabsProps extends BaseElementProps {
6
+ /** Tabs */
7
+ items: Array<TabItem>;
8
+ /** Handler of changing current active item */
9
+ onActiveItemChange: (item: TabItem) => void;
10
+ /**
11
+ * Active item by default.
12
+ * If not set - first item will be active
13
+ */
14
+ defaultActive?: TabItem;
15
+ /**
16
+ * Component size.
17
+ * Default is `normal`
18
+ */
19
+ size?: ElementSize;
20
+ /** Component position */
21
+ position?: TabsPosition;
22
+ /** Component style */
23
+ style?: TabsStyle;
24
+ /** Is component tabs should take all width of parent */
25
+ fullWidth?: boolean;
26
+ }
27
+ /**
28
+ * Tabs panel
29
+ * @throws Items are empty
30
+ */
31
+ declare const Tabs: ({ items, onActiveItemChange, defaultActive, size, position, style, fullWidth, className, title, data, }: TabsProps) => JSX.Element;
32
+ export default Tabs;
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/tabs/component/index.tsx"],"names":[],"mappings":"AAIA,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGtD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGtD,gCAAgC;AAChC,MAAM,WAAW,SAAU,SAAQ,gBAAgB;IAC/C,WAAW;IACX,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAEtB,8CAA8C;IAC9C,kBAAkB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAE5C;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,YAAY,CAAC;IAExB,sBAAsB;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB,wDAAwD;IACxD,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;GAGG;AACH,QAAA,MAAM,IAAI,4GAMP,SAAS,KAAG,WA6Ed,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useState, useEffect, useRef } from "react";
3
+ import { getClassName, isNullOrEmpty, isNullOrUndefined } from "@bodynarf/utils";
4
+ import "./style.scss";
5
+ import { ElementSize } from "../..";
6
+ import { mapDataAttributes } from "../../../utils";
7
+ import { TabsPosition, TabsStyle } from "..";
8
+ import TabItemComponent from "../components/item";
9
+ /**
10
+ * Tabs panel
11
+ * @throws Items are empty
12
+ */
13
+ const Tabs = ({ items, onActiveItemChange, defaultActive, size, position, style, fullWidth, className, title, data, }) => {
14
+ if (items.length === 0) {
15
+ throw new Error("Invalid configuration. Tab items must be defined");
16
+ }
17
+ const [activeItem, setActiveItem] = useState(defaultActive ?? items[0]);
18
+ const isFirstRun = useRef(true);
19
+ const onTabsClick = useCallback((container) => {
20
+ const closestTab = container.target.closest(".bbr-tabs__tab");
21
+ if (isNullOrUndefined(closestTab)) {
22
+ return;
23
+ }
24
+ const itemId = closestTab.attributes.getNamedItem("data-item-id")?.value ?? "";
25
+ if (isNullOrEmpty(itemId)) {
26
+ return;
27
+ }
28
+ const item = items.find(({ id }) => id === itemId);
29
+ if (isNullOrUndefined(item) || item === activeItem) {
30
+ return;
31
+ }
32
+ setActiveItem(item);
33
+ }, [activeItem, items]);
34
+ useEffect(() => {
35
+ if (isFirstRun.current) {
36
+ isFirstRun.current = false;
37
+ return;
38
+ }
39
+ onActiveItemChange(activeItem);
40
+ }, [activeItem, onActiveItemChange]);
41
+ const elClassName = getClassName([
42
+ "bbr-tabs",
43
+ "tabs",
44
+ position ?? TabsPosition.left,
45
+ getSizeClassName(size, [ElementSize.Normal]),
46
+ style ?? TabsStyle.default,
47
+ fullWidth === true ? "is-fullwidth" : "",
48
+ className,
49
+ ]);
50
+ const dataAttributes = isNullOrUndefined(data)
51
+ ? undefined
52
+ : mapDataAttributes(data);
53
+ return (_jsx("nav", { className: elClassName, onClick: onTabsClick, title: title, ...dataAttributes, children: _jsx("ul", { children: items.map(item => _jsx(TabItemComponent, { item: item, activeItem: activeItem.id }, item.id)) }) }));
54
+ };
55
+ export default Tabs;
56
+ /**
57
+ * Get class name for specified size and constraints
58
+ * @param size Component size
59
+ * @param notAllowedSizes Sizes that not applicable to component
60
+ * @returns Class name for react element
61
+ */
62
+ const getSizeClassName = (size, notAllowedSizes) => {
63
+ notAllowedSizes ??= [];
64
+ if (isNullOrUndefined(size) || notAllowedSizes.includes(size)) {
65
+ return "";
66
+ }
67
+ return `is-${size}`;
68
+ };
@@ -0,0 +1,12 @@
1
+ .bbr-tabs {
2
+ &__tab {
3
+ .bbr-icon {
4
+ &:first-child {
5
+ margin-right: 0.5rem;
6
+ }
7
+ &:last-child {
8
+ margin-left: 0.5rem;
9
+ }
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import { TabItem as Item } from "../..";
3
+ /** Tabs panel single tab item component props type */
4
+ export interface TabItemProps {
5
+ /** Tab item */
6
+ item: Item;
7
+ /** Active item identifier */
8
+ activeItem: string;
9
+ }
10
+ /** Tabs panel single tab item component */
11
+ declare const TabItem: ({ item, activeItem }: TabItemProps) => JSX.Element;
12
+ export default TabItem;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/tabs/components/item/index.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,OAAO,CAAC;AAGxC,sDAAsD;AACtD,MAAM,WAAW,YAAY;IACzB,eAAe;IACf,IAAI,EAAE,IAAI,CAAC;IAEX,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,2CAA2C;AAC3C,QAAA,MAAM,OAAO,yBAEV,YAAY,KAAG,WAqBjB,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { getClassName, isNullOrUndefined } from "@bodynarf/utils";
3
+ import Icon from "../../../icon";
4
+ /** Tabs panel single tab item component */
5
+ const TabItem = ({ item, activeItem }) => {
6
+ if (!isNullOrUndefined(item.icon)) {
7
+ return _jsx(TabItemWithIcon, { item: item, activeItem: activeItem });
8
+ }
9
+ const className = getClassName([
10
+ "bbr-tabs__tab",
11
+ activeItem === item.id ? "is-active" : undefined,
12
+ ]);
13
+ return (_jsx("li", { className: className, "data-item-id": item.id, children: _jsx("a", { children: item.caption }) }, item.id));
14
+ };
15
+ export default TabItem;
16
+ /** Tabs panel single tab item with icon component */
17
+ const TabItemWithIcon = ({ item, activeItem }) => {
18
+ const iconConfig = item.icon;
19
+ const className = getClassName([
20
+ "bbr-tabs__tab",
21
+ activeItem === item.id ? "is-active" : undefined,
22
+ ]);
23
+ if (iconConfig.position === "left") {
24
+ return (_jsx("li", { className: className, "data-item-id": item.id, children: _jsxs("a", { children: [_jsx(Icon, { ...iconConfig }), _jsx("span", { children: item.caption })] }) }, item.id));
25
+ }
26
+ return (_jsx("li", { className: className, "data-item-id": item.id, children: _jsxs("a", { children: [_jsx("span", { children: item.caption }), _jsx(Icon, { ...iconConfig })] }) }, item.id));
27
+ };
@@ -0,0 +1,3 @@
1
+ export { default } from "./component";
2
+ export * from "./types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/tabs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from "./component";
2
+ export * from "./types";
@@ -0,0 +1,43 @@
1
+ import { ElementIcon } from "..";
2
+ /** Tabs component style */
3
+ export declare enum TabsStyle {
4
+ /**
5
+ * Default style.
6
+ * Single border at the bottom
7
+ */
8
+ default = "",
9
+ /**
10
+ * Classic style with borders.
11
+ * Borders all except bottom
12
+ */
13
+ boxed = "is-boxed",
14
+ /**
15
+ * Styled as buttons
16
+ */
17
+ radioButton = "is-toggle",
18
+ /**
19
+ * Styled as rounded buttons
20
+ */
21
+ radioButtonRounded = "is-toggle is-toggle-rounded"
22
+ }
23
+ /**
24
+ * Tabs items position on component
25
+ */
26
+ export declare enum TabsPosition {
27
+ /** On the left side. Default value */
28
+ "left" = "",
29
+ /** Center*/
30
+ "center" = "is-centered",
31
+ /** Pulled to right */
32
+ "right" = "is-right"
33
+ }
34
+ /** Tab item */
35
+ export interface TabItem {
36
+ /** Unique identifier across all tab items */
37
+ id: string;
38
+ /** Displayable caption */
39
+ caption: string;
40
+ /** Icon configuration */
41
+ icon?: ElementIcon;
42
+ }
43
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/tabs/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAEjC,2BAA2B;AAC3B,oBAAY,SAAS;IACjB;;;OAGG;IACH,OAAO,KAAK;IAEZ;;;OAGG;IACH,KAAK,aAAa;IAElB;;OAEG;IACH,WAAW,cAAc;IAEzB;;OAEG;IACH,kBAAkB,gCAAgC;CACrD;AAED;;GAEG;AACH,oBAAY,YAAY;IACpB,sCAAsC;IACtC,MAAM,KAAK;IAEX,YAAY;IACZ,QAAQ,gBAAgB;IAExB,sBAAsB;IACtB,OAAO,aAAa;CACvB;AAED,eAAe;AACf,MAAM,WAAW,OAAO;IACpB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IAEX,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAC;IAEhB,yBAAyB;IACzB,IAAI,CAAC,EAAE,WAAW,CAAC;CACtB"}
@@ -0,0 +1,34 @@
1
+ /** Tabs component style */
2
+ export var TabsStyle;
3
+ (function (TabsStyle) {
4
+ /**
5
+ * Default style.
6
+ * Single border at the bottom
7
+ */
8
+ TabsStyle["default"] = "";
9
+ /**
10
+ * Classic style with borders.
11
+ * Borders all except bottom
12
+ */
13
+ TabsStyle["boxed"] = "is-boxed";
14
+ /**
15
+ * Styled as buttons
16
+ */
17
+ TabsStyle["radioButton"] = "is-toggle";
18
+ /**
19
+ * Styled as rounded buttons
20
+ */
21
+ TabsStyle["radioButtonRounded"] = "is-toggle is-toggle-rounded";
22
+ })(TabsStyle || (TabsStyle = {}));
23
+ /**
24
+ * Tabs items position on component
25
+ */
26
+ export var TabsPosition;
27
+ (function (TabsPosition) {
28
+ /** On the left side. Default value */
29
+ TabsPosition["left"] = "";
30
+ /** Center*/
31
+ TabsPosition["center"] = "is-centered";
32
+ /** Pulled to right */
33
+ TabsPosition["right"] = "is-right";
34
+ })(TabsPosition || (TabsPosition = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bodynarf/react.components",
3
- "version": "1.5.8",
3
+ "version": "1.6.1",
4
4
  "author": {
5
5
  "name": "Artem",
6
6
  "email": "bodynar@gmail.com"
package/dist DELETED
@@ -1,32 +0,0 @@
1
- # About
2
- Small library with react components based on Bulma CSS framework&nbsp; <a href="https://bulma.io" title="Bulma css framework">
3
- <img
4
- src="https://bulma.io/images/made-with-bulma.png"
5
- alt="Made with Bulma"
6
- width="128"
7
- height="24"/>
8
- </a>
9
-
10
- ## Installation
11
- 1. Install [React](https://reactjs.org/)
12
- 2. Install [Bulma](https://bulma.io/)
13
- 3. Make sure you imported bulma styles in parent container
14
- 4. *(Optional)* To use **Icon** component - install [Bootstrap Icons](https://icons.getbootstrap.com/) and make sure you imported these styles in parent container
15
-
16
- ## Description
17
- ### Simple components
18
- Simple react components based on html elements.
19
-
20
- - **Date** - date input;
21
- - **Multiline** - multiline text input;
22
- - **Text**- single line text input;
23
- - **Anchor**
24
- - **Button**
25
- - **Icon** - *see p.4 of installation*
26
- - **Dropdown** - custom dropdown component, based on html div elements & css. Allows to use icon in elements
27
-
28
- ### Complex components
29
- Complex components is set of components built via combining simple components or represent complex logical component
30
- - **Search** - Search bar with optional button to perform search
31
- - **Paginator** - Pagination elements to navigate through paged list
32
-