Skip to content

Commit

Permalink
Merge pull request #515 from ably/web-3920-search-data-id
Browse files Browse the repository at this point in the history
[WEB-4042] Add searchDataId Meganav prop
  • Loading branch information
kennethkalmer authored Oct 21, 2024
2 parents 1c5b35d + f1adb67 commit 8ea138b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ably/ui",
"version": "14.7.3",
"version": "14.7.4",
"description": "Home of the Ably design system library ([design.ably.com](https://design.ably.com)). It provides a showcase, development/test environment and a publishing pipeline for different distributables.",
"repository": {
"type": "git",
Expand Down
16 changes: 14 additions & 2 deletions src/core/Meganav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type SignInProps = {
theme: MeganavTheme;
loginLink: string;
absUrl: AbsUrl;
searchDataId?: string;
};

type MeganavProps = {
Expand All @@ -106,14 +107,22 @@ type MeganavProps = {
urlBase?: string;
addSearchApiKey: string;
statusUrl: string;
searchDataId?: string;
};

const SignIn = ({ sessionState, theme, loginLink, absUrl }: SignInProps) => {
const SignIn = ({
sessionState,
theme,
loginLink,
absUrl,
searchDataId,
}: SignInProps) => {
return sessionState.signedIn ? (
<MeganavItemsSignedIn
absUrl={absUrl}
sessionState={sessionState}
theme={theme}
searchDataId={searchDataId}
/>
) : (
<ul className="hidden md:flex items-center">
Expand All @@ -136,7 +145,7 @@ const SignIn = ({ sessionState, theme, loginLink, absUrl }: SignInProps) => {
</a>
</li>
<li className="ui-meganav-item">
<MeganavSearch absUrl={absUrl} />
<MeganavSearch absUrl={absUrl} dataId={searchDataId} />
</li>
<li className="ui-meganav-item">
<a
Expand Down Expand Up @@ -168,6 +177,7 @@ const Meganav = ({
urlBase,
addSearchApiKey,
statusUrl,
searchDataId,
}: MeganavProps) => {
const [sessionState, setSessionState] = useState<MeganavSessionState>();

Expand Down Expand Up @@ -216,6 +226,7 @@ const Meganav = ({
theme={theme}
loginLink={loginLink}
absUrl={absUrl}
searchDataId={searchDataId}
/>
) : (
<SignInPlaceholder />
Expand All @@ -229,6 +240,7 @@ const Meganav = ({
loginLink={loginLink}
absUrl={absUrl}
statusUrl={statusUrl}
searchDataId={searchDataId}
/>
</div>
</nav>
Expand Down
30 changes: 30 additions & 0 deletions src/core/Meganav/Meganav.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,33 @@ const PageSignedIn = () => {
export const SignedIn = {
render: () => <PageSignedIn />,
};

const SignedInWithDataSearchId = () => {
useEffect(() => {
loadIcons();
const store = getRemoteDataStore();
fetchSessionData(store, "/api/me");
fetchBlogPosts(store, "/api/blog");
}, []);

return (
<Meganav
paths={{
logo: "#",
ablyStack: "#",
iconSprites: "#",
blogThumb1: "#",
blogThumb2: "#",
blogThumb3: "#",
}}
statusUrl={statusUrl}
themeName="white"
addSearchApiKey="#"
searchDataId="inkeep-search"
/>
);
};

export const DataSearchId = {
render: () => <SignedInWithDataSearchId />,
};
4 changes: 3 additions & 1 deletion src/core/MeganavItemsMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type MeganavItemsMobileProps = {
loginLink: string;
absUrl: AbsUrl;
statusUrl: string;
searchDataId?: string;
};

const MeganavItemsMobile = ({
Expand All @@ -34,6 +35,7 @@ const MeganavItemsMobile = ({
loginLink,
absUrl,
statusUrl,
searchDataId,
}: MeganavItemsMobileProps) => {
const classNames = `ui-meganav-link ${theme.textColor}`;

Expand Down Expand Up @@ -100,7 +102,7 @@ const MeganavItemsMobile = ({
style={{ maxWidth: "none" }}
placeholder="Search"
autoComplete="off"
data-id="meganav-mobile-search-input"
data-id={searchDataId ?? "meganav-mobile-search-input"}
/>

<MeganavSearchAutocomplete />
Expand Down
4 changes: 3 additions & 1 deletion src/core/MeganavItemsSignedIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type MeganavItemsSignedIn = {
sessionState: MeganavSessionState;
theme: MeganavTheme;
absUrl: AbsUrl;
searchDataId?: string;
};

const truncate = (string: string, length: number) => {
Expand All @@ -17,6 +18,7 @@ const truncate = (string: string, length: number) => {
const MeganavItemsSignedIn = ({
sessionState,
absUrl,
searchDataId,
}: MeganavItemsSignedIn) => {
const accountName = truncate(sessionState.accountName, 20);

Expand All @@ -29,7 +31,7 @@ const MeganavItemsSignedIn = ({
</li>

<li>
<MeganavSearch absUrl={absUrl} />
<MeganavSearch absUrl={absUrl} dataId={searchDataId} />
</li>

{sessionState.account && (
Expand Down
10 changes: 8 additions & 2 deletions src/core/MeganavSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import Icon from "./Icon";
import MeganavSearchPanel from "./MeganavSearchPanel";
import { AbsUrl } from "./Meganav";

const MeganavSearch = ({ absUrl }: { absUrl: AbsUrl }) => (
const MeganavSearch = ({
absUrl,
dataId = "meganav-control",
}: {
absUrl: AbsUrl;
dataId?: string;
}) => (
<>
<button
type="button"
data-id="meganav-control"
data-id={dataId}
data-control="search"
className="h-64 w-24 px-24 pr-48 py-20 group focus:outline-none"
aria-expanded="false"
Expand Down
8 changes: 4 additions & 4 deletions src/core/MeganavSearchSuggestions/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ const MeganavSearchSuggestions = () => {
distance > 0 ? dragLeftEnd(distance, 24) : dragRightEnd(distance, 48);
};

suggestionsToggle.addEventListener("focus", focusSuggestionsHandler);
suggestionsToggle.addEventListener("blur", blurSuggestionsHandler);
suggestionsToggle?.addEventListener("focus", focusSuggestionsHandler);
suggestionsToggle?.addEventListener("blur", blurSuggestionsHandler);
suggestions.addEventListener("touchstart", touchstartHandler);
suggestions.addEventListener("touchmove", touchmoveHandler);
suggestions.addEventListener("touchend", touchendHandler);
suggestions.addEventListener("wheel", wheelHandler);

return {
teardown: () => {
suggestionsToggle.removeEventListener("focus", focusSuggestionsHandler);
suggestionsToggle.removeEventListener("blur", blurSuggestionsHandler);
suggestionsToggle?.removeEventListener("focus", focusSuggestionsHandler);
suggestionsToggle?.removeEventListener("blur", blurSuggestionsHandler);
suggestions.removeEventListener("touchstart", touchstartHandler);
suggestions.removeEventListener("touchmove", touchmoveHandler);
suggestions.removeEventListener("touchend", touchendHandler);
Expand Down

0 comments on commit 8ea138b

Please sign in to comment.