@react-foundry/component-helpers 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 +22 -0
- package/README.md +48 -0
- package/dist/classes.d.ts +15 -0
- package/dist/classes.js +27 -0
- package/dist/classes.mjs +22 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/index.mjs +1 -0
- package/package.json +31 -0
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,48 @@
|
|
|
1
|
+
React Foundry - Component Helpers
|
|
2
|
+
=================================
|
|
3
|
+
|
|
4
|
+
Helper functions for writing components.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Using this package
|
|
8
|
+
------------------
|
|
9
|
+
|
|
10
|
+
First install the package into your project:
|
|
11
|
+
|
|
12
|
+
```shell
|
|
13
|
+
npm install -S @react-foundry/component-helpers
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Then use it in your code as follows:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import componentHelpers from '@react-foundry/component-helpers';
|
|
20
|
+
|
|
21
|
+
// WRITEME
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Working on this package
|
|
27
|
+
-----------------------
|
|
28
|
+
|
|
29
|
+
Before working on this package you must install its dependencies using
|
|
30
|
+
the following command:
|
|
31
|
+
|
|
32
|
+
```shell
|
|
33
|
+
pnpm install
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Building
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
npm run build
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Clean-up
|
|
45
|
+
|
|
46
|
+
```shell
|
|
47
|
+
npm run clean
|
|
48
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Modifiers = string | (string | undefined)[];
|
|
2
|
+
export type StandardProps = {
|
|
3
|
+
/** 'id' attribute to place on the base HTML element */
|
|
4
|
+
id?: string;
|
|
5
|
+
/** Block name override in BEM style classes applied to all elements */
|
|
6
|
+
classBlock?: string;
|
|
7
|
+
/** BEM style modifiers to apply to the base HTML element */
|
|
8
|
+
classModifiers?: Modifiers;
|
|
9
|
+
/** Extra classes to apply to the base HTML element */
|
|
10
|
+
className?: string;
|
|
11
|
+
};
|
|
12
|
+
export type ClassBuilder = (element?: string, elementModifiers?: Modifiers, extra2?: string) => string | undefined;
|
|
13
|
+
export declare const id: <T>(v: T) => T;
|
|
14
|
+
export declare const classBuilder: (blockDefault: string, blockOverride?: string, blockModifiers?: Modifiers, extra?: string) => ClassBuilder;
|
|
15
|
+
export {};
|
package/dist/classes.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.classBuilder = exports.id = void 0;
|
|
4
|
+
// Define a pointless component to coax react-docgen-typescript-loader
|
|
5
|
+
const StandardComponent = (props) => null;
|
|
6
|
+
const id = (v) => v;
|
|
7
|
+
exports.id = id;
|
|
8
|
+
const concatClasses = (...classes) => (
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
classes
|
|
11
|
+
.flat(Infinity)
|
|
12
|
+
.filter(exports.id)
|
|
13
|
+
.join(' ') || undefined);
|
|
14
|
+
const toArray = (v) => (Array.isArray(v)
|
|
15
|
+
? v
|
|
16
|
+
: v && [v]);
|
|
17
|
+
const classBuilder = (blockDefault, blockOverride, blockModifiers, extra) => {
|
|
18
|
+
const block = blockOverride || blockDefault;
|
|
19
|
+
const bModifiers = toArray(blockModifiers);
|
|
20
|
+
return (element, elementModifiers, extra2) => {
|
|
21
|
+
const eModifiers = toArray(elementModifiers);
|
|
22
|
+
return (element
|
|
23
|
+
? concatClasses(`${block}__${element}`, eModifiers?.filter(exports.id).map(modifier => `${block}__${element}--${modifier}`), extra2)
|
|
24
|
+
: concatClasses(`${block}`, bModifiers?.filter(exports.id).map(modifier => `${block}--${modifier}`), extra));
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.classBuilder = classBuilder;
|
package/dist/classes.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Define a pointless component to coax react-docgen-typescript-loader
|
|
2
|
+
const StandardComponent = (props) => null;
|
|
3
|
+
export const id = (v) => v;
|
|
4
|
+
const concatClasses = (...classes) => (
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
classes
|
|
7
|
+
.flat(Infinity)
|
|
8
|
+
.filter(id)
|
|
9
|
+
.join(' ') || undefined);
|
|
10
|
+
const toArray = (v) => (Array.isArray(v)
|
|
11
|
+
? v
|
|
12
|
+
: v && [v]);
|
|
13
|
+
export const classBuilder = (blockDefault, blockOverride, blockModifiers, extra) => {
|
|
14
|
+
const block = blockOverride || blockDefault;
|
|
15
|
+
const bModifiers = toArray(blockModifiers);
|
|
16
|
+
return (element, elementModifiers, extra2) => {
|
|
17
|
+
const eModifiers = toArray(elementModifiers);
|
|
18
|
+
return (element
|
|
19
|
+
? concatClasses(`${block}__${element}`, eModifiers?.filter(id).map(modifier => `${block}__${element}--${modifier}`), extra2)
|
|
20
|
+
: concatClasses(`${block}`, bModifiers?.filter(id).map(modifier => `${block}--${modifier}`), extra));
|
|
21
|
+
};
|
|
22
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './classes';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./classes"), exports);
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './classes';
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-foundry/component-helpers",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Helper functions for writing components.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"/dist"
|
|
16
|
+
],
|
|
17
|
+
"author": "Daniel A.C. Martin <npm@daniel-martin.co.uk> (http://daniel-martin.co.uk/)",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "5.9.3"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
24
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
25
|
+
"build:esm": "tsc -m es2022 && find dist -name '*.js' -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;",
|
|
26
|
+
"build:cjs": "tsc",
|
|
27
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
28
|
+
},
|
|
29
|
+
"module": "dist/index.mjs",
|
|
30
|
+
"typings": "dist/index.d.ts"
|
|
31
|
+
}
|