@monolith-forensics/monolith-ui 1.2.122 → 1.3.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.
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from "react";
2
+ export declare const Tab: React.FC<{
3
+ value: string | number;
4
+ children: ReactNode;
5
+ style?: React.CSSProperties;
6
+ onClick?: () => void;
7
+ disabled?: boolean;
8
+ leftSection?: React.ReactNode;
9
+ rightSection?: React.ReactNode;
10
+ }>;
@@ -0,0 +1,69 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import styled, { css } from "styled-components";
3
+ import Button from "../Button";
4
+ import { useTabs } from "./TabsProvider";
5
+ const StyledTabButton = styled(Button) `
6
+ user-select: none;
7
+ cursor: pointer;
8
+
9
+ border: none;
10
+ border-radius: 0;
11
+
12
+ color: ${({ theme }) => theme.palette.text.secondary};
13
+ font-weight: 500;
14
+
15
+ ${({ orientation }) => orientation === "horizontal" &&
16
+ css `
17
+ border-bottom: 2px solid transparent;
18
+ border-top-left-radius: 5px;
19
+ border-top-right-radius: 5px;
20
+
21
+ &:hover {
22
+ border-top: 0;
23
+ border-left: 0;
24
+ border-right: 0;
25
+ border-bottom: 2px solid transparent;
26
+
27
+ background-color: ${({ theme }) => theme.palette.action.hover};
28
+ }
29
+
30
+ &[data-active="true"] {
31
+ border-bottom-color: ${({ theme }) => theme.palette.primary.main};
32
+ color: ${({ theme }) => theme.palette.primary.main};
33
+ }
34
+ `}
35
+
36
+ ${({ orientation }) => orientation === "vertical" &&
37
+ css `
38
+ width: auto;
39
+ border-right: 2px solid transparent;
40
+ border-bottom-left-radius: 5px;
41
+ border-top-left-radius: 5px;
42
+
43
+ .inner-span {
44
+ justify-content: flex-start !important;
45
+ }
46
+
47
+ &:hover {
48
+ border-top: 0;
49
+ border-left: 0;
50
+ border-bottom: 0;
51
+ border-right: 2px solid transparent;
52
+
53
+ background-color: ${({ theme }) => theme.palette.action.hover};
54
+ }
55
+
56
+ &[data-active="true"] {
57
+ border-right-color: ${({ theme }) => theme.palette.primary.main};
58
+ color: ${({ theme }) => theme.palette.primary.main};
59
+ }
60
+ `}
61
+ `;
62
+ export const Tab = ({ children, style, onClick, disabled, leftSection, rightSection, value, }) => {
63
+ const { size, value: activeValue, onChange, orientation } = useTabs();
64
+ const isActive = activeValue === value;
65
+ return (_jsx(StyledTabButton, { className: "tab-button", style: style, "data-active": isActive, onClick: () => {
66
+ onClick === null || onClick === void 0 ? void 0 : onClick();
67
+ onChange(value);
68
+ }, size: size, disabled: disabled, leftSection: leftSection, rightSection: rightSection, orientation: orientation, children: children }));
69
+ };
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from "react";
2
+ import { Size } from "../core";
3
+ import { Justify, Orientation } from "./Tabs.types";
4
+ export declare const Tabs: React.FC<{
5
+ defaultValue?: string | number;
6
+ value?: string | number;
7
+ onChange?: (value: string | number) => void;
8
+ children: ReactNode;
9
+ size?: Size;
10
+ showDivider?: boolean;
11
+ justify?: Justify;
12
+ orientation?: Orientation;
13
+ }>;
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import styled, { css } from "styled-components";
3
+ import { TabsProvider } from "./TabsProvider";
4
+ const StyledContainer = styled.div `
5
+ user-select: none;
6
+ display: flex;
7
+ flex-wrap: wrap;
8
+ justify-content: ${({ justify }) => justify};
9
+
10
+ ${({ orientation, showDivider, theme }) => orientation === "vertical"
11
+ ? css `
12
+ flex-direction: column;
13
+ border-right: ${showDivider
14
+ ? "1px solid " + theme.palette.divider
15
+ : "transparent"};
16
+ width: max-content;
17
+ `
18
+ : css `
19
+ flex-direction: row;
20
+ border-bottom: ${showDivider
21
+ ? "1px solid " + theme.palette.divider
22
+ : "transparent"};
23
+ `}
24
+
25
+ color: ${({ theme }) => theme.palette.text.secondary};
26
+ `;
27
+ export const Tabs = ({ children, size, showDivider = true, justify = "start", defaultValue, value, onChange, orientation = "horizontal", }) => {
28
+ return (_jsx(TabsProvider, { size: size, value: value, defaultValue: defaultValue, onChange: onChange, orientation: orientation, children: _jsx(StyledContainer, { className: "tabs-container", size: size, showDivider: showDivider, justify: justify, orientation: orientation, children: children }) }));
29
+ };
@@ -0,0 +1,2 @@
1
+ export type Justify = "start" | "center" | "end" | "space-between" | "space-around";
2
+ export type Orientation = "horizontal" | "vertical";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import { Size } from "../core";
2
+ import { Orientation } from "./Tabs.types";
3
+ export declare const TabsContext: import("react").Context<{
4
+ value: string | number;
5
+ defaultValue?: string | number;
6
+ onChange: (value: string | number) => void;
7
+ size?: Size;
8
+ orientation?: Orientation;
9
+ }>;
10
+ export declare const TabsProvider: React.FC<{
11
+ children: React.ReactNode;
12
+ size?: Size;
13
+ value?: string | number;
14
+ defaultValue?: string | number;
15
+ onChange?: (value: string | number) => void;
16
+ orientation?: Orientation;
17
+ }>;
18
+ export declare const useTabs: () => {
19
+ value: string | number;
20
+ defaultValue?: string | number;
21
+ onChange: (value: string | number) => void;
22
+ size?: Size;
23
+ orientation?: Orientation;
24
+ };
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ import { useUncontrolled } from "@mantine/hooks";
4
+ export const TabsContext = createContext({
5
+ value: "",
6
+ defaultValue: "",
7
+ onChange: () => { },
8
+ size: "sm",
9
+ orientation: "horizontal",
10
+ });
11
+ export const TabsProvider = ({ children, size, value, defaultValue, onChange, orientation }) => {
12
+ const [_value, handleChange] = useUncontrolled({
13
+ value,
14
+ defaultValue,
15
+ finalValue: "Final",
16
+ onChange,
17
+ });
18
+ return (_jsx(TabsContext.Provider, { value: {
19
+ value: _value,
20
+ onChange: handleChange,
21
+ size,
22
+ defaultValue,
23
+ orientation,
24
+ }, children: children }));
25
+ };
26
+ export const useTabs = () => {
27
+ const context = useContext(TabsContext);
28
+ if (!context) {
29
+ throw new Error("useTabs must be used within a TabsProvider");
30
+ }
31
+ return context;
32
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./Tabs";
2
+ export * from "./Tab";
@@ -0,0 +1,2 @@
1
+ export * from "./Tabs";
2
+ export * from "./Tab";
package/dist/index.d.ts CHANGED
@@ -40,3 +40,4 @@ export * from "./MonolithUIProvider";
40
40
  export * from "./FileViewer";
41
41
  export * from "./Table";
42
42
  export type { ColumnProps, TableProps } from "./Table";
43
+ export * from "./Tabs";
package/dist/index.js CHANGED
@@ -28,3 +28,4 @@ export * from "./hooks";
28
28
  export * from "./MonolithUIProvider";
29
29
  export * from "./FileViewer";
30
30
  export * from "./Table";
31
+ export * from "./Tabs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.2.122",
3
+ "version": "1.3.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",