@react-foundry/anchor-list 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2019-2025 Crown Copyright
4
+ Copyright (C) 2019-2026 Daniel A.C. Martin
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ of the Software, and to permit persons to whom the Software is furnished to do
11
+ so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ React Foundry - Anchor List
2
+ ===========================
3
+
4
+ A list of anchors. Items that contain links to the current page are
5
+ marked as active. Useful for navigation menus.
6
+
7
+
8
+ Using this package
9
+ ------------------
10
+
11
+ First install the package into your project:
12
+
13
+ ```shell
14
+ npm install -S @react-foundry/anchor-list
15
+ ```
16
+
17
+ Then use it in your code as follows:
18
+
19
+ ```js
20
+ import React, { createElement as h } from 'react';
21
+ import AnchorList from '@react-foundry/anchor-list';
22
+
23
+ export const MyComponent = props => (
24
+ <AnchorList items={[
25
+ { href: '/', text: 'Inactive 1' },
26
+ { href: '#main-content', text: 'Active' },
27
+ { href: '/#main-content', text: 'Inactive 2' }
28
+ ]} />
29
+ );
30
+
31
+ export default MyComponent;
32
+ ```
33
+
34
+
35
+ Working on this package
36
+ -----------------------
37
+
38
+ Before working on this package you must install its dependencies using
39
+ the following command:
40
+
41
+ ```shell
42
+ pnpm install
43
+ ```
44
+
45
+
46
+ ### Testing
47
+
48
+ ```shell
49
+ npm test
50
+ ```
51
+
52
+
53
+ ### Building
54
+
55
+ ```shell
56
+ npm run build
57
+ ```
58
+
59
+
60
+ ### Clean-up
61
+
62
+ ```shell
63
+ npm run clean
64
+ ```
File without changes
@@ -0,0 +1,20 @@
1
+ import { ComponentType, FC, HTMLProps } from 'react';
2
+ import { AnchorProps } from '@react-foundry/anchor';
3
+ import { StandardProps } from '@react-foundry/component-helpers';
4
+ import '../assets/AnchorList.scss';
5
+ export type Anchor = AnchorProps & {
6
+ /** Text of the link */
7
+ text?: string;
8
+ };
9
+ export type Item = Anchor & {
10
+ /** Subitems */
11
+ items?: Item[];
12
+ };
13
+ export type AnchorListProps = StandardProps & {
14
+ /** List component to use */
15
+ as?: ComponentType<HTMLProps<HTMLOListElement | HTMLUListElement>> | 'ol' | 'ul';
16
+ /** List of links to choose from */
17
+ items: Item[];
18
+ };
19
+ export declare const AnchorList: FC<AnchorListProps>;
20
+ export default AnchorList;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.AnchorList = void 0;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ const anchor_1 = require("@react-foundry/anchor");
8
+ const component_helpers_1 = require("@react-foundry/component-helpers");
9
+ const router_1 = require("@react-foundry/router");
10
+ require("../assets/AnchorList.scss");
11
+ const AnchorListInner = ({ as: Component = 'ul', classBlock, classModifiers, className, items, ...attrs }) => {
12
+ const classes = (0, component_helpers_1.classBuilder)('penultimate-anchor-list', classBlock, classModifiers, className);
13
+ const isActive = (0, router_1.useIsActive)();
14
+ const processItem = ({ children, text, href, items, ...anchorAttrs }, i) => {
15
+ const active = isActive(href || '', false);
16
+ return ((0, jsx_runtime_1.jsxs)("li", { className: classes('item', active ? 'active' : undefined), children: [(0, jsx_runtime_1.jsx)(anchor_1.A, { ...anchorAttrs, classBlock: classes('link'), href: href, children: children || text }), !(active && items) ? null : ((0, jsx_runtime_1.jsx)(Component, { className: classes('subitems'), children: items.map(processItem) }))] }, i));
17
+ };
18
+ return ((0, jsx_runtime_1.jsx)(Component, { ...attrs, className: classes(), children: items.map(processItem) }));
19
+ };
20
+ const AnchorList = ({ as: Component = 'ul', classBlock, classModifiers, className, items, ...attrs }) => {
21
+ const classes = (0, component_helpers_1.classBuilder)('penultimate-anchor-list', classBlock, classModifiers, className);
22
+ const props = {
23
+ ...attrs,
24
+ as: Component,
25
+ classBlock,
26
+ classModifiers,
27
+ className,
28
+ items
29
+ };
30
+ const content = ((0, jsx_runtime_1.jsx)(AnchorListInner, { ...props }));
31
+ return (!router_1.needSuspense ? content : ((0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: (0, jsx_runtime_1.jsx)(Component, { ...attrs, className: classes(), children: items.map(({ children, text, href, ...anchorAttrs }, i) => ((0, jsx_runtime_1.jsx)("li", { className: classes('item'), children: (0, jsx_runtime_1.jsx)(anchor_1.A, { ...anchorAttrs, classBlock: classes('link'), href: href, children: children || text }) }, i))) }), children: content })));
32
+ };
33
+ exports.AnchorList = AnchorList;
34
+ exports.default = exports.AnchorList;
@@ -0,0 +1,30 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Suspense } from 'react';
4
+ import { A } from '@react-foundry/anchor';
5
+ import { classBuilder } from '@react-foundry/component-helpers';
6
+ import { needSuspense, useIsActive } from '@react-foundry/router';
7
+ import '../assets/AnchorList.scss';
8
+ const AnchorListInner = ({ as: Component = 'ul', classBlock, classModifiers, className, items, ...attrs }) => {
9
+ const classes = classBuilder('penultimate-anchor-list', classBlock, classModifiers, className);
10
+ const isActive = useIsActive();
11
+ const processItem = ({ children, text, href, items, ...anchorAttrs }, i) => {
12
+ const active = isActive(href || '', false);
13
+ return (_jsxs("li", { className: classes('item', active ? 'active' : undefined), children: [_jsx(A, { ...anchorAttrs, classBlock: classes('link'), href: href, children: children || text }), !(active && items) ? null : (_jsx(Component, { className: classes('subitems'), children: items.map(processItem) }))] }, i));
14
+ };
15
+ return (_jsx(Component, { ...attrs, className: classes(), children: items.map(processItem) }));
16
+ };
17
+ export const AnchorList = ({ as: Component = 'ul', classBlock, classModifiers, className, items, ...attrs }) => {
18
+ const classes = classBuilder('penultimate-anchor-list', classBlock, classModifiers, className);
19
+ const props = {
20
+ ...attrs,
21
+ as: Component,
22
+ classBlock,
23
+ classModifiers,
24
+ className,
25
+ items
26
+ };
27
+ const content = (_jsx(AnchorListInner, { ...props }));
28
+ return (!needSuspense ? content : (_jsx(Suspense, { fallback: _jsx(Component, { ...attrs, className: classes(), children: items.map(({ children, text, href, ...anchorAttrs }, i) => (_jsx("li", { className: classes('item'), children: _jsx(A, { ...anchorAttrs, classBlock: classes('link'), href: href, children: children || text }) }, i))) }), children: content })));
29
+ };
30
+ export default AnchorList;
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@react-foundry/anchor-list",
3
+ "version": "0.1.0",
4
+ "description": "A list of anchors.",
5
+ "main": "dist/AnchorList.js",
6
+ "sass": "assets/AnchorList.scss",
7
+ "exports": {
8
+ ".": {
9
+ "sass": "./assets/AnchorList.scss",
10
+ "types": "./dist/AnchorList.d.ts",
11
+ "import": "./dist/AnchorList.mjs",
12
+ "require": "./dist/AnchorList.js",
13
+ "default": "./dist/AnchorList.mjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "/assets",
18
+ "/dist"
19
+ ],
20
+ "author": "Daniel A.C. Martin <npm@daniel-martin.co.uk> (http://daniel-martin.co.uk/)",
21
+ "license": "MIT",
22
+ "keywords": [
23
+ "react-components"
24
+ ],
25
+ "dependencies": {
26
+ "@react-foundry/anchor": "^0.1.0",
27
+ "@react-foundry/component-helpers": "^0.1.0",
28
+ "@react-foundry/router": "^0.1.0"
29
+ },
30
+ "peerDependencies": {
31
+ "@react-foundry/docs-components": "^0.1.0",
32
+ "@storybook/addon-docs": "^9.1.17",
33
+ "react": "^19.2.3"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@react-foundry/docs-components": {
37
+ "optional": true
38
+ },
39
+ "@storybook/addon-docs": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "devDependencies": {
44
+ "@types/react": "19.2.9",
45
+ "jest": "30.2.0",
46
+ "jest-environment-jsdom": "30.2.0",
47
+ "ts-jest": "29.4.6",
48
+ "typescript": "5.9.3",
49
+ "@react-foundry/component-test-helpers": "0.1.0"
50
+ },
51
+ "scripts": {
52
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
53
+ "build": "npm run build:esm && npm run build:cjs",
54
+ "build:esm": "tsc -m es2022 && find dist -name '*.js' -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;",
55
+ "build:cjs": "tsc",
56
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
57
+ },
58
+ "module": "dist/AnchorList.mjs",
59
+ "typings": "dist/AnchorList.d.ts"
60
+ }