@kkcompany/app-ui 0.1.26 → 0.1.27

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/dist/index.cjs CHANGED
@@ -783,6 +783,16 @@ const onResize = (container, handler) => {
783
783
  observer.observe(container);
784
784
  return () => observer.disconnect();
785
785
  };
786
+ const getLineCount = (el) => {
787
+ const style = window.getComputedStyle(el);
788
+ let lineHeight = Number.parseFloat(style.lineHeight);
789
+ if (Number.isNaN(lineHeight) || lineHeight <= 0) {
790
+ const fontSize = Number.parseFloat(style.fontSize);
791
+ lineHeight = fontSize > 0 ? fontSize * 1.2 : 0;
792
+ }
793
+ if (!lineHeight) return 0;
794
+ return Math.max(1, Math.round(el.scrollHeight / lineHeight));
795
+ };
786
796
  const defaultMessages = {
787
797
  seeMore: "もっと見る",
788
798
  seeLess: "閉じる"
@@ -790,15 +800,16 @@ const defaultMessages = {
790
800
  const SeeMore = ({ style, messages = defaultMessages, children, ...rest }) => {
791
801
  const [status, setStatus] = (0, react.useState)("no-expand");
792
802
  const [expandedHeight, setExpandedHeight] = (0, react.useState)();
803
+ const rootRef = (0, react.useRef)(null);
793
804
  const containeRef = (0, react.useRef)();
794
805
  (0, react.useEffect)(() => {
795
- if (!containeRef.current) return;
796
- return onResize(containeRef.current, () => {
806
+ if (!rootRef.current) return;
807
+ return onResize(rootRef.current, () => {
797
808
  if (!containeRef.current) return;
798
- const { scrollHeight, clientHeight } = containeRef.current;
799
- const fontSize = Number.parseFloat(window.getComputedStyle(containeRef.current).fontSize);
800
- const scrollable = scrollHeight > clientHeight * 1.3;
801
- const fit = fontSize * 3 > scrollHeight;
809
+ const collapsedLines = Number.parseInt(window.getComputedStyle(containeRef.current).getPropertyValue("--see-more-collapsed-lines"), 10) || 2;
810
+ const lineCount = getLineCount(containeRef.current);
811
+ const scrollable = lineCount > collapsedLines;
812
+ const fit = lineCount <= collapsedLines;
802
813
  setStatus((current) => current === "no-expand" && scrollable ? "collapsed" : current !== "no-expand" && fit ? "no-expand" : current);
803
814
  setExpandedHeight(containeRef.current?.scrollHeight);
804
815
  });
@@ -806,6 +817,7 @@ const SeeMore = ({ style, messages = defaultMessages, children, ...rest }) => {
806
817
  const toggle = () => setStatus((current) => current === "collapsed" ? "expanded" : "collapsing");
807
818
  return /* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)("div", {
808
819
  css: [containerStyle, { div: addonStyles[status] }],
820
+ ref: rootRef,
809
821
  ...rest,
810
822
  children: [/* @__PURE__ */ (0, __emotion_react_jsx_runtime.jsxs)("div", {
811
823
  css: [expandedHeight && { "--see-more-max-height": `${expandedHeight}px` }, style],
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react0 from "react";
2
2
  import { ElementType, MouseEventHandler, ReactElement, ReactNode } from "react";
3
- import * as _emotion_react_jsx_runtime0 from "@emotion/react/jsx-runtime";
3
+ import * as _emotion_react_jsx_runtime1 from "@emotion/react/jsx-runtime";
4
4
  import { CSSObject } from "@emotion/react";
5
5
  import Link from "next/link";
6
6
 
@@ -65,7 +65,7 @@ declare const HiddenToggle: ({
65
65
  defaultEnabled?: boolean;
66
66
  children: any;
67
67
  onChange: any;
68
- }) => _emotion_react_jsx_runtime0.JSX.Element;
68
+ }) => _emotion_react_jsx_runtime1.JSX.Element;
69
69
  //#endregion
70
70
  //#region src/Icon.d.ts
71
71
  declare const Icon: ({
@@ -74,7 +74,7 @@ declare const Icon: ({
74
74
  }: {
75
75
  style?: {};
76
76
  src: any;
77
- }) => _emotion_react_jsx_runtime0.JSX.Element;
77
+ }) => _emotion_react_jsx_runtime1.JSX.Element;
78
78
  //#endregion
79
79
  //#region src/SeeMore.d.ts
80
80
  declare const defaultMessages: {
@@ -90,7 +90,7 @@ declare const SeeMore: ({
90
90
  style?: CSSObject;
91
91
  messages?: typeof defaultMessages;
92
92
  children?: ReactNode;
93
- }) => _emotion_react_jsx_runtime0.JSX.Element;
93
+ }) => _emotion_react_jsx_runtime1.JSX.Element;
94
94
  //#endregion
95
95
  //#region src/VideoItem.d.ts
96
96
  type VideoDetail = {
@@ -154,6 +154,6 @@ declare const VideoThumbnail: ({
154
154
  Image?: ElementType;
155
155
  };
156
156
  onClick?: MouseEventHandler<HTMLAnchorElement>;
157
- }) => _emotion_react_jsx_runtime0.JSX.Element;
157
+ }) => _emotion_react_jsx_runtime1.JSX.Element;
158
158
  //#endregion
159
159
  export { Banner, Dropdown, HiddenToggle, Icon, SeeMore, VideoItem, VideoThumbnail };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react0 from "react";
2
2
  import { ElementType, MouseEventHandler, ReactElement, ReactNode } from "react";
3
- import * as _emotion_react_jsx_runtime2 from "@emotion/react/jsx-runtime";
3
+ import * as _emotion_react_jsx_runtime1 from "@emotion/react/jsx-runtime";
4
4
  import { CSSObject } from "@emotion/react";
5
5
  import Link from "next/link";
6
6
 
@@ -65,7 +65,7 @@ declare const HiddenToggle: ({
65
65
  defaultEnabled?: boolean;
66
66
  children: any;
67
67
  onChange: any;
68
- }) => _emotion_react_jsx_runtime2.JSX.Element;
68
+ }) => _emotion_react_jsx_runtime1.JSX.Element;
69
69
  //#endregion
70
70
  //#region src/Icon.d.ts
71
71
  declare const Icon: ({
@@ -74,7 +74,7 @@ declare const Icon: ({
74
74
  }: {
75
75
  style?: {};
76
76
  src: any;
77
- }) => _emotion_react_jsx_runtime2.JSX.Element;
77
+ }) => _emotion_react_jsx_runtime1.JSX.Element;
78
78
  //#endregion
79
79
  //#region src/SeeMore.d.ts
80
80
  declare const defaultMessages: {
@@ -90,7 +90,7 @@ declare const SeeMore: ({
90
90
  style?: CSSObject;
91
91
  messages?: typeof defaultMessages;
92
92
  children?: ReactNode;
93
- }) => _emotion_react_jsx_runtime2.JSX.Element;
93
+ }) => _emotion_react_jsx_runtime1.JSX.Element;
94
94
  //#endregion
95
95
  //#region src/VideoItem.d.ts
96
96
  type VideoDetail = {
@@ -154,6 +154,6 @@ declare const VideoThumbnail: ({
154
154
  Image?: ElementType;
155
155
  };
156
156
  onClick?: MouseEventHandler<HTMLAnchorElement>;
157
- }) => _emotion_react_jsx_runtime2.JSX.Element;
157
+ }) => _emotion_react_jsx_runtime1.JSX.Element;
158
158
  //#endregion
159
159
  export { Banner, Dropdown, HiddenToggle, Icon, SeeMore, VideoItem, VideoThumbnail };
package/dist/index.mjs CHANGED
@@ -783,6 +783,16 @@ const onResize = (container, handler) => {
783
783
  observer.observe(container);
784
784
  return () => observer.disconnect();
785
785
  };
786
+ const getLineCount = (el) => {
787
+ const style = window.getComputedStyle(el);
788
+ let lineHeight = Number.parseFloat(style.lineHeight);
789
+ if (Number.isNaN(lineHeight) || lineHeight <= 0) {
790
+ const fontSize = Number.parseFloat(style.fontSize);
791
+ lineHeight = fontSize > 0 ? fontSize * 1.2 : 0;
792
+ }
793
+ if (!lineHeight) return 0;
794
+ return Math.max(1, Math.round(el.scrollHeight / lineHeight));
795
+ };
786
796
  const defaultMessages = {
787
797
  seeMore: "もっと見る",
788
798
  seeLess: "閉じる"
@@ -790,15 +800,16 @@ const defaultMessages = {
790
800
  const SeeMore = ({ style, messages = defaultMessages, children, ...rest }) => {
791
801
  const [status, setStatus] = useState("no-expand");
792
802
  const [expandedHeight, setExpandedHeight] = useState();
803
+ const rootRef = useRef(null);
793
804
  const containeRef = useRef();
794
805
  useEffect(() => {
795
- if (!containeRef.current) return;
796
- return onResize(containeRef.current, () => {
806
+ if (!rootRef.current) return;
807
+ return onResize(rootRef.current, () => {
797
808
  if (!containeRef.current) return;
798
- const { scrollHeight, clientHeight } = containeRef.current;
799
- const fontSize = Number.parseFloat(window.getComputedStyle(containeRef.current).fontSize);
800
- const scrollable = scrollHeight > clientHeight * 1.3;
801
- const fit = fontSize * 3 > scrollHeight;
809
+ const collapsedLines = Number.parseInt(window.getComputedStyle(containeRef.current).getPropertyValue("--see-more-collapsed-lines"), 10) || 2;
810
+ const lineCount = getLineCount(containeRef.current);
811
+ const scrollable = lineCount > collapsedLines;
812
+ const fit = lineCount <= collapsedLines;
802
813
  setStatus((current) => current === "no-expand" && scrollable ? "collapsed" : current !== "no-expand" && fit ? "no-expand" : current);
803
814
  setExpandedHeight(containeRef.current?.scrollHeight);
804
815
  });
@@ -806,6 +817,7 @@ const SeeMore = ({ style, messages = defaultMessages, children, ...rest }) => {
806
817
  const toggle = () => setStatus((current) => current === "collapsed" ? "expanded" : "collapsing");
807
818
  return /* @__PURE__ */ jsxs("div", {
808
819
  css: [containerStyle, { div: addonStyles[status] }],
820
+ ref: rootRef,
809
821
  ...rest,
810
822
  children: [/* @__PURE__ */ jsxs("div", {
811
823
  css: [expandedHeight && { "--see-more-max-height": `${expandedHeight}px` }, style],
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
1
  {
2
- "name": "@kkcompany/app-ui",
3
- "version": "0.1.26",
4
- "module": "dist/index.mjs",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.mts",
7
- "files": [
8
- "dist"
9
- ],
10
- "sideEffects": false,
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.mjs",
14
- "module": "./dist/index.mjs",
15
- "types": "./dist/index.d.mts",
16
- "require": "./dist/index.cjs"
17
- }
18
- },
19
- "license": "MIT",
20
- "scripts": {
21
- "dev": "next",
22
- "build": "tsdown --format esm --format cjs"
23
- },
24
- "dependencies": {
25
- "@emotion/react": "^11.14.0"
26
- },
27
- "peerDependencies": {
28
- "react": "^16.8.0",
29
- "react-dom": "^16.8.0"
30
- },
31
- "devDependencies": {
32
- "@biomejs/biome": "^2.3.5",
33
- "binary-base64-loader": "^1.0.0",
34
- "next": "^16.0.2",
35
- "rollup-plugin-base64": "^1.0.1",
36
- "tsdown": "^0.16.4",
37
- "typescript": "^5.9.3"
38
- }
2
+ "name": "@kkcompany/app-ui",
3
+ "version": "0.1.27",
4
+ "module": "dist/index.mjs",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.mts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "sideEffects": false,
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.mjs",
14
+ "module": "./dist/index.mjs",
15
+ "types": "./dist/index.d.mts",
16
+ "require": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "license": "MIT",
20
+ "scripts": {
21
+ "dev": "next",
22
+ "build": "tsdown --format esm --format cjs"
23
+ },
24
+ "dependencies": {
25
+ "@emotion/react": "^11.14.0"
26
+ },
27
+ "peerDependencies": {
28
+ "react": "^16.8.0",
29
+ "react-dom": "^16.8.0"
30
+ },
31
+ "devDependencies": {
32
+ "@biomejs/biome": "^2.3.5",
33
+ "binary-base64-loader": "^1.0.0",
34
+ "next": "^16.0.2",
35
+ "rollup-plugin-base64": "^1.0.1",
36
+ "tsdown": "^0.16.4",
37
+ "typescript": "^5.9.3"
38
+ }
39
39
  }