@equinor/cpl-compact-autocomplete 0.0.1

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/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Equinor ASA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ [<-- Go back](../../README.md)
2
+
3
+ # @equinor/cpl-compact-autocomplete
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ yarn add @equinor/cpl-compact-autocomplete
9
+ ```
@@ -0,0 +1,15 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { AutocompleteProps } from '@equinor/eds-core-react';
3
+ import * as styled_components_dist_types from 'styled-components/dist/types';
4
+ import * as styled_components from 'styled-components';
5
+ import * as react from 'react';
6
+
7
+ interface CompactAutocompleteProps<T> extends Omit<AutocompleteProps<T>, 'ref'> {
8
+ }
9
+ declare function CompactAutocomplete<T>({ id, label, ...props }: CompactAutocompleteProps<T>): react_jsx_runtime.JSX.Element;
10
+
11
+ declare const CompactAutocompleteLabel: styled_components_dist_types.IStyledComponentBase<"web", styled_components.FastOmit<react.DetailedHTMLProps<react.LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, never>> & string;
12
+
13
+ declare const CompactAutocompleteWrapper: styled_components_dist_types.IStyledComponentBase<"web", styled_components.FastOmit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
14
+
15
+ export { CompactAutocomplete, CompactAutocompleteLabel, type CompactAutocompleteProps, CompactAutocompleteWrapper };
@@ -0,0 +1,15 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { AutocompleteProps } from '@equinor/eds-core-react';
3
+ import * as styled_components_dist_types from 'styled-components/dist/types';
4
+ import * as styled_components from 'styled-components';
5
+ import * as react from 'react';
6
+
7
+ interface CompactAutocompleteProps<T> extends Omit<AutocompleteProps<T>, 'ref'> {
8
+ }
9
+ declare function CompactAutocomplete<T>({ id, label, ...props }: CompactAutocompleteProps<T>): react_jsx_runtime.JSX.Element;
10
+
11
+ declare const CompactAutocompleteLabel: styled_components_dist_types.IStyledComponentBase<"web", styled_components.FastOmit<react.DetailedHTMLProps<react.LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, never>> & string;
12
+
13
+ declare const CompactAutocompleteWrapper: styled_components_dist_types.IStyledComponentBase<"web", styled_components.FastOmit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
14
+
15
+ export { CompactAutocomplete, CompactAutocompleteLabel, type CompactAutocompleteProps, CompactAutocompleteWrapper };
package/dist/index.js ADDED
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __objRest = (source, exclude) => {
23
+ var target = {};
24
+ for (var prop in source)
25
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
26
+ target[prop] = source[prop];
27
+ if (source != null && __getOwnPropSymbols)
28
+ for (var prop of __getOwnPropSymbols(source)) {
29
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
30
+ target[prop] = source[prop];
31
+ }
32
+ return target;
33
+ };
34
+ var __export = (target, all) => {
35
+ for (var name in all)
36
+ __defProp(target, name, { get: all[name], enumerable: true });
37
+ };
38
+ var __copyProps = (to, from, except, desc) => {
39
+ if (from && typeof from === "object" || typeof from === "function") {
40
+ for (let key of __getOwnPropNames(from))
41
+ if (!__hasOwnProp.call(to, key) && key !== except)
42
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
43
+ }
44
+ return to;
45
+ };
46
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
47
+ // If the importer is in node compatibility mode or this is not an ESM
48
+ // file that has been converted to a CommonJS file using a Babel-
49
+ // compatible transform (i.e. "__esModule" has not been set), then set
50
+ // "default" to the CommonJS "module.exports" for node compatibility.
51
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
52
+ mod
53
+ ));
54
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
55
+
56
+ // src/index.ts
57
+ var src_exports = {};
58
+ __export(src_exports, {
59
+ CompactAutocomplete: () => CompactAutocomplete,
60
+ CompactAutocompleteLabel: () => CompactAutocompleteLabel,
61
+ CompactAutocompleteWrapper: () => CompactAutocompleteWrapper
62
+ });
63
+ module.exports = __toCommonJS(src_exports);
64
+
65
+ // src/CompactAutocomplete.tsx
66
+ var import_eds_core_react = require("@equinor/eds-core-react");
67
+ var import_eds_tokens2 = require("@equinor/eds-tokens");
68
+ var import_react = require("react");
69
+ var import_styled_components3 = __toESM(require("styled-components"));
70
+
71
+ // src/CompactAutocompleteLabel.tsx
72
+ var import_eds_tokens = require("@equinor/eds-tokens");
73
+ var import_styled_components = __toESM(require("styled-components"));
74
+ var CompactAutocompleteLabel = import_styled_components.default.label`
75
+ align-self: stretch;
76
+
77
+ display: flex;
78
+ align-items: center;
79
+ padding: 0;
80
+
81
+ font-weight: 400;
82
+
83
+ background-color: ${import_eds_tokens.tokens.colors.interactive.disabled__fill.rgba};
84
+
85
+ padding-left: 0.75rem;
86
+ padding-right: 0.5rem;
87
+
88
+ border-top-left-radius: 10rem;
89
+ border-bottom-left-radius: 10rem;
90
+ `;
91
+
92
+ // src/CompactAutocompleteWrapper.tsx
93
+ var import_styled_components2 = __toESM(require("styled-components"));
94
+ var CompactAutocompleteWrapper = import_styled_components2.default.div`
95
+ display: flex;
96
+ align-items: center;
97
+
98
+ --font-size: 0.75rem;
99
+
100
+ font-size: var(--font-size);
101
+ `;
102
+
103
+ // src/CompactAutocomplete.tsx
104
+ var import_jsx_runtime = require("react/jsx-runtime");
105
+ function CompactAutocomplete(_a) {
106
+ var _b = _a, { id, label } = _b, props = __objRest(_b, ["id", "label"]);
107
+ const autocompleteId = (0, import_react.useMemo)(() => id != null ? id : crypto.randomUUID(), [id]);
108
+ const labelId = (0, import_react.useMemo)(() => crypto.randomUUID(), []);
109
+ const { multiple, optionLabel, selectedOptions } = props;
110
+ const placeholder = (0, import_react.useMemo)(() => {
111
+ if (!multiple) {
112
+ return void 0;
113
+ }
114
+ const selectedLabels = optionLabel ? selectedOptions == null ? void 0 : selectedOptions.map((option) => optionLabel(option)) : selectedOptions;
115
+ return selectedLabels == null ? void 0 : selectedLabels.join(", ");
116
+ }, [multiple, optionLabel, selectedOptions]);
117
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CompactAutocompleteWrapper, { children: [
118
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CompactAutocompleteLabel, { id: labelId, htmlFor: autocompleteId, children: label }),
119
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CPLAutocompleteWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
120
+ import_eds_core_react.Autocomplete,
121
+ __spreadValues({
122
+ id: autocompleteId,
123
+ label: null,
124
+ "aria-labelledby": labelId,
125
+ placeholder
126
+ }, props)
127
+ ) })
128
+ ] });
129
+ }
130
+ var CPLAutocompleteWrapper = import_styled_components3.default.div`
131
+ div:has(input) {
132
+ box-shadow: none;
133
+ background-color: ${import_eds_tokens2.tokens.colors.ui.background__light.rgba};
134
+ border-top-right-radius: 10rem;
135
+ border-bottom-right-radius: 10rem;
136
+ }
137
+
138
+ & input {
139
+ font-size: inherit;
140
+ font-weight: 400;
141
+ padding-top: 2px;
142
+ padding-bottom: 2px;
143
+ padding-left: 0.5rem;
144
+ padding-left: 0.5rem;
145
+ line-height: 1;
146
+
147
+ &::placeholder {
148
+ color: inherit;
149
+ }
150
+ }
151
+
152
+ // Override right padding of button placement
153
+ & input + div {
154
+ padding-right: 0.25rem;
155
+ }
156
+
157
+ & button {
158
+ // Change icon color
159
+ color: ${import_eds_tokens2.tokens.colors.text.static_icons__default.rgba};
160
+
161
+ & svg {
162
+ height: 1rem;
163
+ width: 1rem;
164
+ }
165
+ }
166
+ `;
167
+ // Annotate the CommonJS export names for ESM import in node:
168
+ 0 && (module.exports = {
169
+ CompactAutocomplete,
170
+ CompactAutocompleteLabel,
171
+ CompactAutocompleteWrapper
172
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,136 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
29
+
30
+ // src/CompactAutocomplete.tsx
31
+ import { Autocomplete } from "@equinor/eds-core-react";
32
+ import { tokens as tokens2 } from "@equinor/eds-tokens";
33
+ import { useMemo } from "react";
34
+ import styled3 from "styled-components";
35
+
36
+ // src/CompactAutocompleteLabel.tsx
37
+ import { tokens } from "@equinor/eds-tokens";
38
+ import styled from "styled-components";
39
+ var CompactAutocompleteLabel = styled.label`
40
+ align-self: stretch;
41
+
42
+ display: flex;
43
+ align-items: center;
44
+ padding: 0;
45
+
46
+ font-weight: 400;
47
+
48
+ background-color: ${tokens.colors.interactive.disabled__fill.rgba};
49
+
50
+ padding-left: 0.75rem;
51
+ padding-right: 0.5rem;
52
+
53
+ border-top-left-radius: 10rem;
54
+ border-bottom-left-radius: 10rem;
55
+ `;
56
+
57
+ // src/CompactAutocompleteWrapper.tsx
58
+ import styled2 from "styled-components";
59
+ var CompactAutocompleteWrapper = styled2.div`
60
+ display: flex;
61
+ align-items: center;
62
+
63
+ --font-size: 0.75rem;
64
+
65
+ font-size: var(--font-size);
66
+ `;
67
+
68
+ // src/CompactAutocomplete.tsx
69
+ import { jsx, jsxs } from "react/jsx-runtime";
70
+ function CompactAutocomplete(_a) {
71
+ var _b = _a, { id, label } = _b, props = __objRest(_b, ["id", "label"]);
72
+ const autocompleteId = useMemo(() => id != null ? id : crypto.randomUUID(), [id]);
73
+ const labelId = useMemo(() => crypto.randomUUID(), []);
74
+ const { multiple, optionLabel, selectedOptions } = props;
75
+ const placeholder = useMemo(() => {
76
+ if (!multiple) {
77
+ return void 0;
78
+ }
79
+ const selectedLabels = optionLabel ? selectedOptions == null ? void 0 : selectedOptions.map((option) => optionLabel(option)) : selectedOptions;
80
+ return selectedLabels == null ? void 0 : selectedLabels.join(", ");
81
+ }, [multiple, optionLabel, selectedOptions]);
82
+ return /* @__PURE__ */ jsxs(CompactAutocompleteWrapper, { children: [
83
+ /* @__PURE__ */ jsx(CompactAutocompleteLabel, { id: labelId, htmlFor: autocompleteId, children: label }),
84
+ /* @__PURE__ */ jsx(CPLAutocompleteWrapper, { children: /* @__PURE__ */ jsx(
85
+ Autocomplete,
86
+ __spreadValues({
87
+ id: autocompleteId,
88
+ label: null,
89
+ "aria-labelledby": labelId,
90
+ placeholder
91
+ }, props)
92
+ ) })
93
+ ] });
94
+ }
95
+ var CPLAutocompleteWrapper = styled3.div`
96
+ div:has(input) {
97
+ box-shadow: none;
98
+ background-color: ${tokens2.colors.ui.background__light.rgba};
99
+ border-top-right-radius: 10rem;
100
+ border-bottom-right-radius: 10rem;
101
+ }
102
+
103
+ & input {
104
+ font-size: inherit;
105
+ font-weight: 400;
106
+ padding-top: 2px;
107
+ padding-bottom: 2px;
108
+ padding-left: 0.5rem;
109
+ padding-left: 0.5rem;
110
+ line-height: 1;
111
+
112
+ &::placeholder {
113
+ color: inherit;
114
+ }
115
+ }
116
+
117
+ // Override right padding of button placement
118
+ & input + div {
119
+ padding-right: 0.25rem;
120
+ }
121
+
122
+ & button {
123
+ // Change icon color
124
+ color: ${tokens2.colors.text.static_icons__default.rgba};
125
+
126
+ & svg {
127
+ height: 1rem;
128
+ width: 1rem;
129
+ }
130
+ }
131
+ `;
132
+ export {
133
+ CompactAutocomplete,
134
+ CompactAutocompleteLabel,
135
+ CompactAutocompleteWrapper
136
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@equinor/cpl-compact-autocomplete",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist/**"
10
+ ],
11
+ "dependencies": {
12
+ "@equinor/eds-icons": "^0.21.0",
13
+ "@equinor/eds-tokens": "^0.9.2"
14
+ },
15
+ "devDependencies": {
16
+ "@equinor/eds-core-react": "^0.42.1",
17
+ "@storybook/react": "^8.1.11",
18
+ "@storybook/test": "^8.1.11",
19
+ "@types/react": "^18.3.3",
20
+ "@types/react-dom": "^18.3.0",
21
+ "@types/styled-components": "^5.1.34",
22
+ "eslint": "^8.56.0",
23
+ "react": "^18.2.0",
24
+ "react-dom": "^18.2.0",
25
+ "styled-components": "^6.1.11",
26
+ "tsup": "^8.1.0",
27
+ "eslint-config-custom": "0.0.5",
28
+ "tsconfig": "0.0.1"
29
+ },
30
+ "peerDependencies": {
31
+ "@equinor/eds-core-react": ">=0.42.1",
32
+ "react": ">=18.2.0",
33
+ "react-dom": ">=18.2.0",
34
+ "styled-components": ">=5.3.11"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup src/index.ts --format esm,cjs --dts --external react",
41
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
42
+ "dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react",
43
+ "lint": "TIMING=1 eslint . --fix"
44
+ }
45
+ }