@greghowe79/the-lib 0.2.0 → 0.2.2

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,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("@builder.io/qwik/jsx-runtime");
4
+ const qwik = require("@builder.io/qwik");
5
+ const qwikCity = require("@builder.io/qwik-city");
6
+ const NavLink = qwik.component$(({ activeClass, ...props }) => {
7
+ const location = qwikCity.useLocation();
8
+ const toPathname = props.href ?? "";
9
+ const locationPathname = location.url.pathname;
10
+ const startSlashPosition = toPathname !== "/" && toPathname.startsWith("/") ? toPathname.length - 1 : toPathname.length;
11
+ const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
12
+ const isActive = locationPathname === toPathname || locationPathname.endsWith(toPathname) && (locationPathname.charAt(endSlashPosition) === "/" || locationPathname.charAt(startSlashPosition) === "/");
13
+ return /* @__PURE__ */ jsxRuntime.jsx(qwikCity.Link, {
14
+ ...props,
15
+ class: [
16
+ props.class,
17
+ isActive && activeClass ? activeClass : ""
18
+ ],
19
+ children: /* @__PURE__ */ jsxRuntime.jsx(qwik.Slot, {})
20
+ });
21
+ });
22
+ exports.NavLink = NavLink;
@@ -0,0 +1,22 @@
1
+ import { jsx } from "@builder.io/qwik/jsx-runtime";
2
+ import { component$, Slot } from "@builder.io/qwik";
3
+ import { useLocation, Link } from "@builder.io/qwik-city";
4
+ const NavLink = component$(({ activeClass, ...props }) => {
5
+ const location = useLocation();
6
+ const toPathname = props.href ?? "";
7
+ const locationPathname = location.url.pathname;
8
+ const startSlashPosition = toPathname !== "/" && toPathname.startsWith("/") ? toPathname.length - 1 : toPathname.length;
9
+ const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
10
+ const isActive = locationPathname === toPathname || locationPathname.endsWith(toPathname) && (locationPathname.charAt(endSlashPosition) === "/" || locationPathname.charAt(startSlashPosition) === "/");
11
+ return /* @__PURE__ */ jsx(Link, {
12
+ ...props,
13
+ class: [
14
+ props.class,
15
+ isActive && activeClass ? activeClass : ""
16
+ ],
17
+ children: /* @__PURE__ */ jsx(Slot, {})
18
+ });
19
+ });
20
+ export {
21
+ NavLink
22
+ };
@@ -2,12 +2,11 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("@builder.io/qwik/jsx-runtime");
4
4
  const qwik = require("@builder.io/qwik");
5
- const qwikCity = require("@builder.io/qwik-city");
5
+ const NavLink = require("./NavLink.qwik.cjs");
6
6
  const styles = require("./styles.css.qwik.cjs");
7
7
  const button = require("../button/button.qwik.cjs");
8
8
  require("@fontsource/roboto-condensed/500.css");
9
9
  const NavigationMenu = qwik.component$(({ ariaLabel, logoComponent, listItems, actions }) => {
10
- const location = qwikCity.useLocation();
11
10
  qwik.useStyles$(styles);
12
11
  return /* @__PURE__ */ jsxRuntime.jsx("nav", {
13
12
  class: "menu",
@@ -18,7 +17,7 @@ const NavigationMenu = qwik.component$(({ ariaLabel, logoComponent, listItems, a
18
17
  /* @__PURE__ */ jsxRuntime.jsxs("div", {
19
18
  class: "menu-left",
20
19
  children: [
21
- /* @__PURE__ */ jsxRuntime.jsx(qwikCity.Link, {
20
+ /* @__PURE__ */ jsxRuntime.jsx(NavLink.NavLink, {
22
21
  href: "/",
23
22
  "aria-label": "Homepage",
24
23
  children: logoComponent && logoComponent({}, null, 0)
@@ -26,12 +25,11 @@ const NavigationMenu = qwik.component$(({ ariaLabel, logoComponent, listItems, a
26
25
  /* @__PURE__ */ jsxRuntime.jsx("ul", {
27
26
  class: "menu-list",
28
27
  children: listItems?.map((item) => {
29
- const isActive = location.url.pathname === item.href;
30
28
  return /* @__PURE__ */ jsxRuntime.jsx("li", {
31
- children: /* @__PURE__ */ jsxRuntime.jsx(qwikCity.Link, {
29
+ children: /* @__PURE__ */ jsxRuntime.jsx(NavLink.NavLink, {
32
30
  href: item.href,
33
31
  class: "menu-link",
34
- "aria-current": isActive ? "page" : void 0,
32
+ activeClass: "active-link",
35
33
  children: item.label
36
34
  })
37
35
  }, item.label);
@@ -1,11 +1,10 @@
1
1
  import { jsx, jsxs } from "@builder.io/qwik/jsx-runtime";
2
2
  import { component$, useStyles$ } from "@builder.io/qwik";
3
- import { useLocation, Link } from "@builder.io/qwik-city";
3
+ import { NavLink } from "./NavLink.qwik.mjs";
4
4
  import styles from "./styles.css.qwik.mjs";
5
5
  import { Button } from "../button/button.qwik.mjs";
6
6
  import "@fontsource/roboto-condensed/500.css";
7
7
  const NavigationMenu = component$(({ ariaLabel, logoComponent, listItems, actions }) => {
8
- const location = useLocation();
9
8
  useStyles$(styles);
10
9
  return /* @__PURE__ */ jsx("nav", {
11
10
  class: "menu",
@@ -16,7 +15,7 @@ const NavigationMenu = component$(({ ariaLabel, logoComponent, listItems, action
16
15
  /* @__PURE__ */ jsxs("div", {
17
16
  class: "menu-left",
18
17
  children: [
19
- /* @__PURE__ */ jsx(Link, {
18
+ /* @__PURE__ */ jsx(NavLink, {
20
19
  href: "/",
21
20
  "aria-label": "Homepage",
22
21
  children: logoComponent && logoComponent({}, null, 0)
@@ -24,12 +23,11 @@ const NavigationMenu = component$(({ ariaLabel, logoComponent, listItems, action
24
23
  /* @__PURE__ */ jsx("ul", {
25
24
  class: "menu-list",
26
25
  children: listItems?.map((item) => {
27
- const isActive = location.url.pathname === item.href;
28
26
  return /* @__PURE__ */ jsx("li", {
29
- children: /* @__PURE__ */ jsx(Link, {
27
+ children: /* @__PURE__ */ jsx(NavLink, {
30
28
  href: item.href,
31
29
  class: "menu-link",
32
- "aria-current": isActive ? "page" : void 0,
30
+ activeClass: "active-link",
33
31
  children: item.label
34
32
  })
35
33
  }, item.label);
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
- const styles = ".menu {\r\n background-color: #fff;\r\n padding: 1rem;\r\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);\r\n}\r\n.menu-container {\r\n max-width: 75rem;\r\n margin: 0 auto;\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n}\r\n.menu-left {\r\n display: flex;\r\n align-items: center;\r\n gap: 2rem;\r\n}\r\n.menu-list {\r\n display: flex;\r\n list-style: none;\r\n gap: 1.5rem;\r\n margin: 0;\r\n padding: 0;\r\n}\r\n\r\n.menu-link {\r\n display: inline-block;\r\n padding: 0.5rem 1rem;\r\n color: #333;\r\n text-decoration: none;\r\n border-radius: 4px;\r\n font-family: 'Roboto Condensed', sans-serif;\r\n transition:\r\n background-color 0.2s,\r\n color 0.2s;\r\n}\r\n\r\n.menu-link:hover,\r\n.menu-link[aria-current='page'] {\r\n background-color: #f0f0f0;\r\n color: #333;\r\n}\r\n.menu-right {\r\n display: flex;\r\n gap: 0.75rem;\r\n}\r\n";
2
+ const styles = ".menu {\r\n background-color: #fff;\r\n padding: 1rem;\r\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);\r\n}\r\n.menu-container {\r\n max-width: 75rem;\r\n margin: 0 auto;\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n}\r\n.menu-left {\r\n display: flex;\r\n align-items: center;\r\n gap: 2rem;\r\n}\r\n.menu-list {\r\n display: flex;\r\n list-style: none;\r\n gap: 1.5rem;\r\n margin: 0;\r\n padding: 0;\r\n}\r\n\r\n.menu-link {\r\n display: inline-block;\r\n padding: 0.5rem 1rem;\r\n color: #333;\r\n text-decoration: none;\r\n border-radius: 4px;\r\n font-family: 'Roboto Condensed', sans-serif;\r\n transition:\r\n background-color 0.2s,\r\n color 0.2s;\r\n}\r\n\r\n.menu-link:hover {\r\n background-color: #f0f0f0;\r\n color: #333;\r\n}\r\n\r\n.active-link {\r\n background-color: #f0f0f0;\r\n color: #333;\r\n}\r\n.menu-right {\r\n display: flex;\r\n gap: 0.75rem;\r\n}\r\n";
3
3
  module.exports = styles;
@@ -1,4 +1,4 @@
1
- const styles = ".menu {\r\n background-color: #fff;\r\n padding: 1rem;\r\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);\r\n}\r\n.menu-container {\r\n max-width: 75rem;\r\n margin: 0 auto;\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n}\r\n.menu-left {\r\n display: flex;\r\n align-items: center;\r\n gap: 2rem;\r\n}\r\n.menu-list {\r\n display: flex;\r\n list-style: none;\r\n gap: 1.5rem;\r\n margin: 0;\r\n padding: 0;\r\n}\r\n\r\n.menu-link {\r\n display: inline-block;\r\n padding: 0.5rem 1rem;\r\n color: #333;\r\n text-decoration: none;\r\n border-radius: 4px;\r\n font-family: 'Roboto Condensed', sans-serif;\r\n transition:\r\n background-color 0.2s,\r\n color 0.2s;\r\n}\r\n\r\n.menu-link:hover,\r\n.menu-link[aria-current='page'] {\r\n background-color: #f0f0f0;\r\n color: #333;\r\n}\r\n.menu-right {\r\n display: flex;\r\n gap: 0.75rem;\r\n}\r\n";
1
+ const styles = ".menu {\r\n background-color: #fff;\r\n padding: 1rem;\r\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);\r\n}\r\n.menu-container {\r\n max-width: 75rem;\r\n margin: 0 auto;\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n}\r\n.menu-left {\r\n display: flex;\r\n align-items: center;\r\n gap: 2rem;\r\n}\r\n.menu-list {\r\n display: flex;\r\n list-style: none;\r\n gap: 1.5rem;\r\n margin: 0;\r\n padding: 0;\r\n}\r\n\r\n.menu-link {\r\n display: inline-block;\r\n padding: 0.5rem 1rem;\r\n color: #333;\r\n text-decoration: none;\r\n border-radius: 4px;\r\n font-family: 'Roboto Condensed', sans-serif;\r\n transition:\r\n background-color 0.2s,\r\n color 0.2s;\r\n}\r\n\r\n.menu-link:hover {\r\n background-color: #f0f0f0;\r\n color: #333;\r\n}\r\n\r\n.active-link {\r\n background-color: #f0f0f0;\r\n color: #333;\r\n}\r\n.menu-right {\r\n display: flex;\r\n gap: 0.75rem;\r\n}\r\n";
2
2
  export {
3
3
  styles as default
4
4
  };
@@ -0,0 +1,6 @@
1
+ import { type LinkProps } from '@builder.io/qwik-city';
2
+ type NavLinkProps = LinkProps & {
3
+ activeClass?: string;
4
+ };
5
+ export declare const NavLink: import("@builder.io/qwik").Component<NavLinkProps>;
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greghowe79/the-lib",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Collection of fast components for Qwik",
5
5
  "main": "./lib/index.qwik.mjs",
6
6
  "qwik": "./lib/index.qwik.mjs",