@lanaco/lnc-react-ui 2.1.42 → 3.0.0-rc.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.
- package/custom-addons/ThemeSelector.js +111 -0
- package/custom-addons/register.js +16 -0
- package/custom-addons/theme-selector.css +17 -0
- package/jest.config.js +7 -0
- package/lib/index.esm.js +79523 -42413
- package/lib/index.js +79604 -42440
- package/package.json +34 -11
- package/rc1 +0 -0
- package/test/jest/__mocks__/styleMock.js +1 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// OutlineSelector.js
|
|
2
|
+
|
|
3
|
+
import React, { memo, useState } from "react";
|
|
4
|
+
import { useGlobals } from "@storybook/api";
|
|
5
|
+
import {
|
|
6
|
+
Icons,
|
|
7
|
+
IconButton,
|
|
8
|
+
} from "@storybook/components";
|
|
9
|
+
import { createPortal } from "react-dom";
|
|
10
|
+
import { useRef } from "react";
|
|
11
|
+
import styled from "@emotion/styled";
|
|
12
|
+
import { themes } from "../src/_utils/theme";
|
|
13
|
+
import "./theme-selector.css"
|
|
14
|
+
|
|
15
|
+
const StyledTooltip = styled.div`
|
|
16
|
+
position: absolute;
|
|
17
|
+
width: 180px;
|
|
18
|
+
z-index: 2147483647;
|
|
19
|
+
filter: drop-shadow(0px 5px 5px rgba(0, 0, 0, 0.05))
|
|
20
|
+
drop-shadow(0 1px 3px rgba(0, 0, 0, 0.1));
|
|
21
|
+
border-radius: 8px;
|
|
22
|
+
font-size: 12px;
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
const Item = styled.div`
|
|
26
|
+
padding: 7px 15px;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
font-weight: 400;
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
const Triangle = styled.div`
|
|
32
|
+
position: absolute;
|
|
33
|
+
border-style: solid;
|
|
34
|
+
-webkit-transform: translate3d(8px, 0px, 0px);
|
|
35
|
+
-moz-transform: translate3d(8px, 0px, 0px);
|
|
36
|
+
-ms-transform: translate3d(8px, 0px, 0px);
|
|
37
|
+
transform: translate3d(8px, 0px, 0px);
|
|
38
|
+
bottom: autopx;
|
|
39
|
+
top: -8px;
|
|
40
|
+
right: autopx;
|
|
41
|
+
left: autopx;
|
|
42
|
+
border-bottom-width: 8px;
|
|
43
|
+
border-top-width: 0px;
|
|
44
|
+
border-right-width: 8px;
|
|
45
|
+
border-left-width: 8px;
|
|
46
|
+
border-top-color: transparent;
|
|
47
|
+
border-left-color: transparent;
|
|
48
|
+
border-right-color: transparent;
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
export const ThemeSelector = memo(() => {
|
|
52
|
+
const [globals, updateGlobals] = useGlobals();
|
|
53
|
+
const buttonRef = useRef();
|
|
54
|
+
const [toggleTooltip, setToggleTooltip] = useState();
|
|
55
|
+
|
|
56
|
+
const changeTheme = (themeName) => {
|
|
57
|
+
setToggleTooltip((prev) => !prev);
|
|
58
|
+
updateGlobals({
|
|
59
|
+
theme: themeName,
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div ref={buttonRef}>
|
|
65
|
+
<IconButton
|
|
66
|
+
style={{ position: "relative" }}
|
|
67
|
+
key="outline"
|
|
68
|
+
active={globals["theme"]}
|
|
69
|
+
title="Apply themes to the preview"
|
|
70
|
+
onClick={() => setToggleTooltip((prev) => !prev)}
|
|
71
|
+
>
|
|
72
|
+
<Icons icon="photo" />
|
|
73
|
+
</IconButton>
|
|
74
|
+
{toggleTooltip &&
|
|
75
|
+
createPortal(
|
|
76
|
+
<>
|
|
77
|
+
<Triangle
|
|
78
|
+
className="tooltip-triangle-lnc"
|
|
79
|
+
style={{
|
|
80
|
+
position: "absolute",
|
|
81
|
+
transform: "translate(74px)",
|
|
82
|
+
top: buttonRef?.current?.getBoundingClientRect()?.bottom + 5,
|
|
83
|
+
left: buttonRef?.current?.getBoundingClientRect()?.left - 70,
|
|
84
|
+
}}
|
|
85
|
+
></Triangle>
|
|
86
|
+
<StyledTooltip
|
|
87
|
+
className="tooltip-lnc"
|
|
88
|
+
style={{
|
|
89
|
+
top: buttonRef?.current?.getBoundingClientRect()?.bottom + 12,
|
|
90
|
+
left: buttonRef?.current?.getBoundingClientRect()?.left - 90,
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
{themes.map((theme, i) => (
|
|
94
|
+
<Item
|
|
95
|
+
key={i}
|
|
96
|
+
style={{
|
|
97
|
+
color:
|
|
98
|
+
globals["theme"] === theme?.name ? "#FF4785" : "unset",
|
|
99
|
+
}}
|
|
100
|
+
onClick={() => changeTheme(theme?.name)}
|
|
101
|
+
>
|
|
102
|
+
{theme?.name}
|
|
103
|
+
</Item>
|
|
104
|
+
))}
|
|
105
|
+
</StyledTooltip>
|
|
106
|
+
</>,
|
|
107
|
+
document.body
|
|
108
|
+
)}
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { addons, types } from '@storybook/addons';
|
|
4
|
+
|
|
5
|
+
import { ThemeSelector } from './ThemeSelector';
|
|
6
|
+
|
|
7
|
+
const ADDON_ID = 'smyaddon';
|
|
8
|
+
|
|
9
|
+
addons.register(ADDON_ID, () => {
|
|
10
|
+
addons.add(ADDON_ID, {
|
|
11
|
+
title: 'Theme',
|
|
12
|
+
type: types.TOOL,
|
|
13
|
+
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
|
|
14
|
+
render: () => <ThemeSelector />,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.dark .tooltip-lnc {
|
|
2
|
+
background: rgba(0, 0, 0, 0.95);
|
|
3
|
+
color: white;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.light .tooltip-lnc{
|
|
7
|
+
background: rgba(255,255,255,0.95);
|
|
8
|
+
color: black;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.dark .tooltip-triangle-lnc {
|
|
12
|
+
border-bottom-color: rgba(0, 0, 0, 0.95);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.light .tooltip-triangle-lnc{
|
|
16
|
+
border-bottom-color: rgba(255,255,255,0.95);
|
|
17
|
+
}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//Jest is hitting CSS imports and trying to parse them as if they were JavaScript.
|
|
2
|
+
//The moduleNameMapper setting tells Jest how to interpret files with different extensions.
|
|
3
|
+
module.exports = {
|
|
4
|
+
moduleNameMapper: {
|
|
5
|
+
'\\.(css|less)$': '<rootDir>/test/jest/__mocks__/styleMock.js',
|
|
6
|
+
},
|
|
7
|
+
};
|