Skip to content

Commit 1023c9e

Browse files
Merge pull request #61 from vtexdocs/feat/small-feedback-section-style
feat
2 parents 1abe338 + 314a36a commit 1023c9e

File tree

10 files changed

+239
-176
lines changed

10 files changed

+239
-176
lines changed

dist/index.d.mts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ interface Item extends SubItem {
2828
interface Props$3 {
2929
/** List of headings in the current documentation page */
3030
headingList?: Item[];
31+
children?: React.ReactNode;
3132
}
3233
/** Table of contents for documentation pages. */
33-
declare const TableOfContents: ({ headingList }: Props$3) => react_jsx_runtime.JSX.Element;
34+
declare const TableOfContents: ({ headingList, children }: Props$3) => react_jsx_runtime.JSX.Element;
3435

3536
interface SideBarSectionState {
3637
/** Array containing the name of the parents of the expanded page in the menu. */
@@ -59,9 +60,11 @@ interface DocPath {
5960
shareButton?: boolean;
6061
/** Function that executes when the user sends the feedback. The function receives the user comment and whether it was a positive (liked = true) or negative feedback. */
6162
sendFeedback: (comment: string, liked: boolean) => Promise<void>;
63+
/** Whether to render the small version of the component or not. */
64+
small?: boolean;
6265
}
6366
/** Component that can be used on each documentation page, so the user can give feedback of whether or not it has helpful. When liked or disliked it opens a modal with a field to add a comment and send feedback. */
64-
declare const FeedbackSection: ({ slug, urlToEdit, suggestEdits, shareButton, sendFeedback, }: DocPath) => react_jsx_runtime.JSX.Element;
67+
declare const FeedbackSection: ({ slug, urlToEdit, suggestEdits, shareButton, sendFeedback, small, }: DocPath) => react_jsx_runtime.JSX.Element;
6568

6669
declare const Search: () => react_jsx_runtime.JSX.Element;
6770

dist/index.mjs

Lines changed: 116 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -6767,8 +6767,11 @@ import AnimateHeight from "react-animate-height";
67676767
// src/lib/table-of-contents/styles.ts
67686768
var itemsContainer = {
67696769
position: "sticky",
6770-
top: "calc(5rem + 32px)",
6771-
borderLeft: "1px solid #E7E9EE"
6770+
top: "calc(5rem + 32px)"
6771+
};
6772+
var headings = {
6773+
borderLeft: "1px solid #E7E9EE",
6774+
mb: "16px"
67726775
};
67736776
var item = (level, active) => {
67746777
const defaultLineHeight = `${level === 1 ? 18 : 22}px`;
@@ -6797,33 +6800,33 @@ var subItemsContainer = {
67976800
ml: "16px",
67986801
borderLeft: "1px solid #E7E9EE"
67996802
};
6800-
var styles_default6 = { itemsContainer, item, subItemsContainer };
6803+
var styles_default6 = { itemsContainer, item, subItemsContainer, headings };
68016804

68026805
// src/lib/table-of-contents/TableOfContents.tsx
68036806
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
6804-
var TableOfContents = ({ headingList }) => {
6807+
var TableOfContents = ({ headingList, children }) => {
68056808
const router = useRouter();
68066809
const { headingItems, activeItem, setHeadingItems, setActiveItem } = useContext2(LibraryContext);
68076810
useEffect5(() => {
6808-
const headings = headingList ?? [];
6809-
if (!headings.length) {
6811+
const headings2 = headingList ?? [];
6812+
if (!headings2.length) {
68106813
document.querySelectorAll("h2, h3").forEach((heading) => {
68116814
const headingSlug = heading.id;
68126815
const item2 = {
68136816
title: removeHTML(heading.innerHTML).replace(":", ""),
68146817
slug: headingSlug
68156818
};
68166819
if (heading.tagName === "H2") {
6817-
headings.push({ ...item2, children: [] });
6818-
} else if (headings.length > 0) {
6819-
headings[headings.length - 1].children.push({ ...item2 });
6820+
headings2.push({ ...item2, children: [] });
6821+
} else if (headings2.length > 0) {
6822+
headings2[headings2.length - 1].children.push({ ...item2 });
68206823
} else {
6821-
headings.push({ ...item2, children: [] });
6824+
headings2.push({ ...item2, children: [] });
68226825
}
68236826
});
6824-
setHeadingItems(headings);
6827+
setHeadingItems(headings2);
68256828
} else
6826-
setHeadingItems(headings);
6829+
setHeadingItems(headings2);
68276830
}, [router.asPath, headingList]);
68286831
const Item = ({
68296832
title: title6,
@@ -6845,34 +6848,37 @@ var TableOfContents = ({ headingList }) => {
68456848
}
68466849
);
68476850
};
6848-
return /* @__PURE__ */ jsx11(Box7, { sx: styles_default6.itemsContainer, "data-cy": "table-of-contents", children: headingItems.map((item2) => /* @__PURE__ */ jsxs7(Box7, { children: [
6849-
/* @__PURE__ */ jsx11(
6850-
Item,
6851-
{
6852-
title: item2.title,
6853-
slug: item2.slug,
6854-
level: 1,
6855-
active: item2.slug === activeItem.item
6856-
}
6857-
),
6858-
/* @__PURE__ */ jsx11(
6859-
AnimateHeight,
6860-
{
6861-
duration: 300,
6862-
height: item2.slug === activeItem.item ? "auto" : 0,
6863-
children: /* @__PURE__ */ jsx11(Box7, { sx: styles_default6.subItemsContainer, children: item2.children.map((subItem) => /* @__PURE__ */ jsx11(
6864-
Item,
6865-
{
6866-
title: subItem.title,
6867-
slug: subItem.slug,
6868-
level: 2,
6869-
active: subItem.slug === activeItem.subItem
6870-
},
6871-
subItem.slug
6872-
)) })
6873-
}
6874-
)
6875-
] }, item2.slug)) });
6851+
return /* @__PURE__ */ jsxs7(Box7, { sx: styles_default6.itemsContainer, "data-cy": "table-of-contents", children: [
6852+
/* @__PURE__ */ jsx11(Box7, { sx: styles_default6.headings, children: headingItems.map((item2) => /* @__PURE__ */ jsxs7(Box7, { children: [
6853+
/* @__PURE__ */ jsx11(
6854+
Item,
6855+
{
6856+
title: item2.title,
6857+
slug: item2.slug,
6858+
level: 1,
6859+
active: item2.slug === activeItem.item
6860+
}
6861+
),
6862+
/* @__PURE__ */ jsx11(
6863+
AnimateHeight,
6864+
{
6865+
duration: 300,
6866+
height: item2.slug === activeItem.item ? "auto" : 0,
6867+
children: /* @__PURE__ */ jsx11(Box7, { sx: styles_default6.subItemsContainer, children: item2.children.map((subItem) => /* @__PURE__ */ jsx11(
6868+
Item,
6869+
{
6870+
title: subItem.title,
6871+
slug: subItem.slug,
6872+
level: 2,
6873+
active: subItem.slug === activeItem.subItem
6874+
},
6875+
subItem.slug
6876+
)) })
6877+
}
6878+
)
6879+
] }, item2.slug)) }),
6880+
children
6881+
] });
68766882
};
68776883
var TableOfContents_default = TableOfContents;
68786884

@@ -9612,28 +9618,37 @@ var like_selected_icon_default = LikeSelectedIcon;
96129618
import { useContext as useContext12, useRef as useRef10, useState as useState12 } from "react";
96139619

96149620
// src/lib/feedback-section/styles.ts
9615-
var container5 = {
9621+
var container5 = ({ small } = {}) => ({
96169622
width: "100%",
96179623
paddingBottom: "16px",
9618-
borderBottom: ["none", "1px solid #E7E9EE"],
9619-
flexDirection: ["column", "row"],
9620-
alignItems: "center",
9624+
borderBottom: small ? "none" : ["none", "1px solid #E7E9EE"],
9625+
flexDirection: small ? "column" : ["column", "row"],
9626+
alignItems: small ? "flex-start" : "center",
96219627
alignContent: ["initial", "space-between"],
96229628
justifyContent: ["initial", "space-between"],
9623-
marginTop: "32px",
9624-
marginBottom: "16px"
9625-
};
9626-
var question = {
9627-
fontSize: "16px",
9628-
lineHeight: "18px"
9629-
};
9629+
marginTop: small ? "0px" : "32px",
9630+
marginBottom: "16px",
9631+
gap: small ? "8px" : "0px"
9632+
});
9633+
var question = ({ small } = {}) => ({
9634+
fontSize: small ? "12px" : "16px",
9635+
lineHeight: "18px",
9636+
color: "#4A596B"
9637+
});
9638+
var iconsContainer = ({ small } = {}) => ({
9639+
display: "flex",
9640+
alignItems: "center",
9641+
gap: small ? "2px" : "4px",
9642+
ml: small ? "3px" : "6px"
9643+
});
96309644
var likeContainer = {
96319645
paddingBottom: ["16px", "0"],
96329646
borderBottom: ["1px solid #E7E9EE", "none"],
96339647
mt: ["8px", "0"],
96349648
mb: ["16px", "0"],
96359649
width: ["100%", "auto"],
9636-
justifyContent: ["center", "initial"]
9650+
justifyContent: ["center", "initial"],
9651+
alignItems: "center"
96379652
};
96389653
var likeIcon = {
96399654
mr: "2px"
@@ -9661,22 +9676,22 @@ var buttonActive = {
96619676
var selectedButton = {
96629677
color: "muted.1"
96639678
};
9664-
var box = {
9679+
var box = ({ small } = {}) => ({
96659680
alignItems: "center",
96669681
color: "muted.0",
9667-
fontSize: "16px",
9682+
fontSize: small ? "12px" : "16px",
96689683
lineHeight: "22px"
9669-
};
9670-
var editContainer = {
9671-
...box,
9684+
});
9685+
var editContainer = ({ small } = {}) => ({
9686+
...box({ small }),
96729687
...button,
96739688
":hover": {
96749689
color: "#000711 !important"
96759690
},
96769691
// ml: ['0', 'auto'],
96779692
color: "#4A596B !important",
96789693
display: "flex"
9679-
};
9694+
});
96809695
var editIcon = { mr: "4px" };
96819696
var shareButton = {
96829697
// ml: ['0', 'auto'],
@@ -9693,17 +9708,17 @@ var styles_default16 = {
96939708
button,
96949709
buttonActive,
96959710
selectedButton,
9696-
shareButton
9711+
shareButton,
9712+
iconsContainer
96979713
};
96989714

96999715
// src/lib/feedback-section/functions.ts
97009716
var setButtonStyle = (feedback, modalState, like) => {
97019717
const buttonactive = modalState.modalOpen && like === modalState.liked ? styles_default16.buttonActive : styles_default16.button;
9702-
const ml = like ? ["0", "8px"] : feedback === like ? ["0", "8px"] : ["32px", "16px"];
97039718
if (feedback === void 0)
9704-
return { ...styles_default16.box, ...buttonactive, ml };
9719+
return { ...styles_default16.box, ...buttonactive };
97059720
if (like === feedback)
9706-
return { ...styles_default16.box, ...styles_default16.selectedButton, ml };
9721+
return { ...styles_default16.box, ...styles_default16.selectedButton };
97079722
return { display: "none !important" };
97089723
};
97099724

@@ -10224,7 +10239,8 @@ var FeedbackSection = ({
1022410239
urlToEdit,
1022510240
suggestEdits = true,
1022610241
shareButton: shareButton2 = false,
10227-
sendFeedback
10242+
sendFeedback,
10243+
small = false
1022810244
}) => {
1022910245
const [feedback, changeFeedback] = useState12(void 0);
1023010246
const [prevSlug, setPrevSlug] = useState12(slug);
@@ -10245,44 +10261,52 @@ var FeedbackSection = ({
1024510261
liked: choice
1024610262
});
1024710263
};
10248-
return /* @__PURE__ */ jsxs41(Flex16, { sx: styles_default16.container, "data-cy": "feedback-section", children: [
10264+
return /* @__PURE__ */ jsxs41(Flex16, { sx: styles_default16.container({ small }), "data-cy": "feedback-section", children: [
1024910265
/* @__PURE__ */ jsxs41(Flex16, { sx: styles_default16.likeContainer, children: [
10250-
/* @__PURE__ */ jsx52(Text12, { sx: styles_default16.question, children: feedback !== void 0 ? messages[locale]["feedback_section.response"] : messages[locale]["feedback_section.question"] }),
10251-
/* @__PURE__ */ jsxs41(
10252-
Flex16,
10253-
{
10254-
ref: likeButton,
10255-
sx: setButtonStyle(feedback, modalState, true),
10256-
onClick: feedback === void 0 ? () => openModal(true) : null,
10257-
"data-cy": "feedback-section-like",
10258-
children: [
10259-
feedback === void 0 || !feedback ? /* @__PURE__ */ jsx52(like_icon_default, { size: 24, sx: styles_default16.likeIcon }) : /* @__PURE__ */ jsx52(like_selected_icon_default, { size: 24, sx: styles_default16.likeIcon }),
10260-
/* @__PURE__ */ jsx52(Text12, { children: messages[locale]["feedback_section.positive"] })
10261-
]
10262-
}
10263-
),
10264-
/* @__PURE__ */ jsxs41(
10265-
Flex16,
10266-
{
10267-
ref: dislikeButton,
10268-
sx: setButtonStyle(feedback, modalState, false),
10269-
onClick: feedback === void 0 ? () => openModal(false) : null,
10270-
children: [
10271-
feedback === void 0 || feedback ? /* @__PURE__ */ jsx52(like_icon_default, { size: 24, sx: styles_default16.dislikeIcon }) : /* @__PURE__ */ jsx52(like_selected_icon_default, { size: 24, sx: styles_default16.dislikeIcon }),
10272-
/* @__PURE__ */ jsx52(Text12, { children: messages[locale]["feedback_section.negative"] })
10273-
]
10274-
}
10275-
)
10266+
/* @__PURE__ */ jsx52(Text12, { sx: styles_default16.question({ small }), children: feedback !== void 0 ? messages[locale]["feedback_section.response"] : messages[locale]["feedback_section.question"] }),
10267+
/* @__PURE__ */ jsxs41(Flex16, { sx: styles_default16.iconsContainer, children: [
10268+
/* @__PURE__ */ jsxs41(
10269+
Flex16,
10270+
{
10271+
ref: likeButton,
10272+
sx: setButtonStyle(feedback, modalState, true),
10273+
onClick: feedback === void 0 ? () => openModal(true) : null,
10274+
"data-cy": "feedback-section-like",
10275+
children: [
10276+
feedback === void 0 || !feedback ? /* @__PURE__ */ jsx52(like_icon_default, { size: small ? 18 : 24, sx: styles_default16.likeIcon }) : /* @__PURE__ */ jsx52(like_selected_icon_default, { size: small ? 18 : 24, sx: styles_default16.likeIcon }),
10277+
!small && /* @__PURE__ */ jsx52(Text12, { children: messages[locale]["feedback_section.positive"] })
10278+
]
10279+
}
10280+
),
10281+
/* @__PURE__ */ jsxs41(
10282+
Flex16,
10283+
{
10284+
ref: dislikeButton,
10285+
sx: setButtonStyle(feedback, modalState, false),
10286+
onClick: feedback === void 0 ? () => openModal(false) : null,
10287+
children: [
10288+
feedback === void 0 || feedback ? /* @__PURE__ */ jsx52(like_icon_default, { size: small ? 18 : 24, sx: styles_default16.dislikeIcon }) : /* @__PURE__ */ jsx52(
10289+
like_selected_icon_default,
10290+
{
10291+
size: small ? 18 : 24,
10292+
sx: styles_default16.dislikeIcon
10293+
}
10294+
),
10295+
!small && /* @__PURE__ */ jsx52(Text12, { children: messages[locale]["feedback_section.negative"] })
10296+
]
10297+
}
10298+
)
10299+
] })
1027610300
] }),
1027710301
suggestEdits && /* @__PURE__ */ jsxs41(
1027810302
Link8,
1027910303
{
1028010304
target: "_blank",
1028110305
rel: "noopener noreferrer",
1028210306
href: urlToEdit,
10283-
sx: styles_default16.editContainer,
10307+
sx: styles_default16.editContainer({ small }),
1028410308
children: [
10285-
/* @__PURE__ */ jsx52(edit_icon_default, { size: 24, sx: styles_default16.editIcon }),
10309+
/* @__PURE__ */ jsx52(edit_icon_default, { size: small ? 18 : 24, sx: styles_default16.editIcon }),
1028610310
/* @__PURE__ */ jsx52(Text12, { children: messages[locale]["feedback_section.edit"] })
1028710311
]
1028810312
}

dist/index.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/feedback-section/FeedbackSection.stories.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const meta = {
99
},
1010
tags: ['autodocs'],
1111
argTypes: {
12-
sendFeedback: () => alert('Send feedback')
12+
sendFeedback: () => alert('Send feedback'),
1313
},
1414
} satisfies Meta<typeof FeedbackSection>
1515

@@ -18,6 +18,7 @@ type Story = StoryObj<typeof meta>
1818

1919
export const SimpleFeedbackSection: Story = {
2020
args: {
21-
sendFeedback: async () => alert('Send feedback')
21+
sendFeedback: async () => alert('Send feedback'),
22+
small: true,
2223
},
2324
}

src/lib/feedback-section/functions.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ export const setButtonStyle = (
1111
modalState.modalOpen && like === modalState.liked
1212
? styles.buttonActive
1313
: styles.button
14-
const ml = like
15-
? ['0', '8px']
16-
: feedback === like
17-
? ['0', '8px']
18-
: ['32px', '16px']
19-
if (feedback === undefined) return { ...styles.box, ...buttonactive, ml }
20-
if (like === feedback) return { ...styles.box, ...styles.selectedButton, ml }
14+
if (feedback === undefined) return { ...styles.box, ...buttonactive }
15+
if (like === feedback) return { ...styles.box, ...styles.selectedButton }
2116
return { display: 'none !important' }
2217
}

0 commit comments

Comments
 (0)