@react-cupertino-ui/search-bar 0.0.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,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Anderson Lima
4
+
5
+ This project is inspired by Apple's design principles but is not affiliated with, endorsed, or sponsored by Apple Inc.
6
+
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/dist/index.css ADDED
@@ -0,0 +1,180 @@
1
+ .react-cupertino-ui-search-bar {
2
+ position: relative;
3
+ width: 100%;
4
+ padding: 8px 16px;
5
+ z-index: 10;
6
+ }
7
+ .react-cupertino-ui-search-bar__container {
8
+ display: flex;
9
+ align-items: center;
10
+ position: relative;
11
+ overflow: hidden;
12
+ }
13
+ .react-cupertino-ui-search-bar__input-wrapper {
14
+ flex: 1;
15
+ display: flex;
16
+ align-items: center;
17
+ height: 36px;
18
+ background: rgba(118, 118, 128, 0.12);
19
+ border-radius: 10px;
20
+ padding: 0 8px;
21
+ transition: background-color 0.2s ease;
22
+ }
23
+ @media (prefers-color-scheme: dark) {
24
+ .react-cupertino-ui-search-bar__input-wrapper {
25
+ background: rgba(118, 118, 128, 0.24);
26
+ }
27
+ }
28
+ .react-cupertino-ui-search-bar__input-wrapper:focus-within {
29
+ background: rgba(118, 118, 128, 0.12);
30
+ }
31
+ .react-cupertino-ui-search-bar__input-wrapper .search-icon {
32
+ color: var(--muted-foreground);
33
+ margin-right: 6px;
34
+ flex-shrink: 0;
35
+ }
36
+ .react-cupertino-ui-search-bar__input-wrapper .spinner {
37
+ width: 16px;
38
+ height: 16px;
39
+ border: 2px solid var(--muted-foreground);
40
+ border-top-color: transparent;
41
+ border-radius: 50%;
42
+ animation: spin 0.8s linear infinite;
43
+ }
44
+ .react-cupertino-ui-search-bar__input {
45
+ flex: 1;
46
+ border: none;
47
+ background: transparent;
48
+ height: 100%;
49
+ font-size: 17px;
50
+ color: var(--foreground);
51
+ min-width: 0;
52
+ }
53
+ .react-cupertino-ui-search-bar__input:focus {
54
+ outline: none;
55
+ }
56
+ .react-cupertino-ui-search-bar__input::placeholder {
57
+ color: var(--muted-foreground);
58
+ }
59
+ .react-cupertino-ui-search-bar .clear-button {
60
+ display: flex;
61
+ align-items: center;
62
+ justify-content: center;
63
+ width: 18px;
64
+ height: 18px;
65
+ border-radius: 50%;
66
+ background: var(--muted-foreground);
67
+ color: var(--background);
68
+ border: none;
69
+ padding: 0;
70
+ margin-left: 6px;
71
+ cursor: pointer;
72
+ }
73
+ .react-cupertino-ui-search-bar .clear-button svg {
74
+ display: block;
75
+ }
76
+ .react-cupertino-ui-search-bar .voice-button {
77
+ background: transparent;
78
+ border: none;
79
+ color: var(--muted-foreground);
80
+ padding: 0;
81
+ margin-left: 6px;
82
+ cursor: pointer;
83
+ display: flex;
84
+ align-items: center;
85
+ }
86
+ .react-cupertino-ui-search-bar .voice-button:hover {
87
+ color: var(--foreground);
88
+ }
89
+ .react-cupertino-ui-search-bar__cancel {
90
+ background: transparent;
91
+ border: none;
92
+ color: var(--color-blue);
93
+ font-size: 17px;
94
+ padding: 0 0 0 12px;
95
+ cursor: pointer;
96
+ white-space: nowrap;
97
+ margin-right: -70px;
98
+ opacity: 0;
99
+ transition: margin-right 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
100
+ pointer-events: none;
101
+ }
102
+ .react-cupertino-ui-search-bar.is-focused .react-cupertino-ui-search-bar__cancel {
103
+ margin-right: 0;
104
+ opacity: 1;
105
+ pointer-events: auto;
106
+ }
107
+ .react-cupertino-ui-search-bar__suggestions {
108
+ position: absolute;
109
+ top: 100%;
110
+ left: 0;
111
+ right: 0;
112
+ background: var(--background);
113
+ background: rgba(255, 255, 255, 0.95);
114
+ backdrop-filter: blur(20px) saturate(var(--glass-saturation, 180%));
115
+ -webkit-backdrop-filter: blur(20px) saturate(var(--glass-saturation, 180%));
116
+ border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.18));
117
+ box-shadow: var(--glass-shadow, 0 8px 32px rgba(0, 0, 0, 0.12));
118
+ position: relative;
119
+ overflow: hidden;
120
+ }
121
+ .react-cupertino-ui-search-bar__suggestions::before {
122
+ content: "";
123
+ position: absolute;
124
+ inset: 0;
125
+ background: var(--glass-highlight, linear-gradient(135deg, rgba(255, 255, 255, 0.4) 0%, transparent 55%));
126
+ border-radius: inherit;
127
+ opacity: var(--glass-highlight-opacity, 0.95);
128
+ pointer-events: none;
129
+ mix-blend-mode: screen;
130
+ }
131
+ .react-cupertino-ui-search-bar__suggestions {
132
+ border-radius: 12px;
133
+ margin: 8px 16px;
134
+ padding: 8px 0;
135
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
136
+ }
137
+ .react-cupertino-ui-search-bar__suggestions .suggestions-list {
138
+ list-style: none;
139
+ padding: 0;
140
+ margin: 0;
141
+ }
142
+ .react-cupertino-ui-search-bar__suggestions .suggestion-item {
143
+ display: flex;
144
+ align-items: center;
145
+ width: 100%;
146
+ padding: 10px 16px;
147
+ background: transparent;
148
+ border: none;
149
+ text-align: left;
150
+ font-size: 16px;
151
+ color: var(--foreground);
152
+ cursor: pointer;
153
+ }
154
+ .react-cupertino-ui-search-bar__suggestions .suggestion-item .suggestion-icon {
155
+ margin-right: 12px;
156
+ color: var(--muted-foreground);
157
+ opacity: 0.7;
158
+ }
159
+ .react-cupertino-ui-search-bar__suggestions .suggestion-item:hover {
160
+ background: rgba(0, 0, 0, 0.05);
161
+ }
162
+ .react-cupertino-ui-search-bar__suggestions .suggestion-item {
163
+ position: relative;
164
+ }
165
+ .react-cupertino-ui-search-bar__suggestions .suggestion-item:not(:last-child)::after {
166
+ content: "";
167
+ position: absolute;
168
+ bottom: 0;
169
+ left: 44px;
170
+ right: 0;
171
+ height: 1px;
172
+ background: var(--border);
173
+ opacity: 0.5;
174
+ }
175
+
176
+ @keyframes spin {
177
+ to {
178
+ transform: rotate(360deg);
179
+ }
180
+ }
@@ -0,0 +1,18 @@
1
+ import * as React from "react";
2
+ import "./index.scss";
3
+ export interface SearchBarProps extends React.InputHTMLAttributes<HTMLInputElement> {
4
+ value: string;
5
+ onChangeValue?: (value: string) => void;
6
+ onCancel?: () => void;
7
+ onSearch?: (value: string) => void;
8
+ placeholder?: string;
9
+ cancelLabel?: string;
10
+ loading?: boolean;
11
+ glass?: boolean;
12
+ suggestions?: string[];
13
+ onSelectSuggestion?: (suggestion: string) => void;
14
+ showVoice?: boolean;
15
+ onVoicePress?: () => void;
16
+ }
17
+ declare const SearchBar: React.ForwardRefExoticComponent<SearchBarProps & React.RefAttributes<HTMLInputElement>>;
18
+ export { SearchBar };
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { Search, X, Mic } from "lucide-react";
4
+ import { cn } from "@react-cupertino-ui/shared/lib/utils";
5
+ import "./index.scss";
6
+ const SearchBar = React.forwardRef(({ className, value, onChangeValue, onCancel, onSearch, placeholder = "Search", cancelLabel = "Cancel", loading = false, glass = true, suggestions = [], onSelectSuggestion, showVoice = true, onVoicePress, ...props }, ref) => {
7
+ const [isFocused, setIsFocused] = React.useState(false);
8
+ const inputRef = React.useRef(null);
9
+ React.useImperativeHandle(ref, () => inputRef.current);
10
+ const handleChange = (e) => {
11
+ onChangeValue?.(e.target.value);
12
+ };
13
+ const handleClear = () => {
14
+ onChangeValue?.("");
15
+ inputRef.current?.focus();
16
+ };
17
+ const handleCancel = () => {
18
+ onChangeValue?.("");
19
+ setIsFocused(false);
20
+ onCancel?.();
21
+ inputRef.current?.blur();
22
+ };
23
+ const handleFocus = (e) => {
24
+ setIsFocused(true);
25
+ props.onFocus?.(e);
26
+ };
27
+ const handleKeyDown = (e) => {
28
+ if (e.key === "Enter") {
29
+ onSearch?.(value);
30
+ }
31
+ props.onKeyDown?.(e);
32
+ };
33
+ // We handle blur via a click outside listener or just keep it simple.
34
+ // iOS behavior: Cancel button appears when focused.
35
+ const showCancel = isFocused || (value && value.length > 0);
36
+ return (_jsxs("div", { className: cn("react-cupertino-ui-search-bar", glass && "glass", isFocused && "is-focused", className), children: [_jsxs("div", { className: "react-cupertino-ui-search-bar__container", children: [_jsxs("div", { className: "react-cupertino-ui-search-bar__input-wrapper", children: [_jsx(Search, { className: "search-icon", size: 16 }), _jsx("input", { ref: inputRef, type: "text", className: "react-cupertino-ui-search-bar__input", value: value, onChange: handleChange, onFocus: handleFocus, onKeyDown: handleKeyDown, onBlur: (e) => {
37
+ props.onBlur?.(e);
38
+ // We don't set isFocused false here immediately to allow interactions
39
+ // But standard behavior is: Cancel button stays until 'Cancel' is pressed or user manually cancels?
40
+ // Actually on iOS, 'Cancel' button is always there if focused. If user clicks 'Cancel', it blurs.
41
+ // If user clicks outside, it might blur but 'Cancel' button usually hides only if text is empty?
42
+ // Let's rely on manual Cancel press for hiding the button fully effectively in this UI pattern
43
+ }, placeholder: placeholder, ...props }), loading && _jsx("div", { className: "spinner" }), !loading && value.length > 0 && (_jsx("button", { type: "button", className: "clear-button", onClick: handleClear, children: _jsx(X, { size: 12, fill: "currentColor" }) })), !loading && value.length === 0 && showVoice && (_jsx("button", { type: "button", className: "voice-button", onClick: onVoicePress, children: _jsx(Mic, { size: 16 }) }))] }), _jsx("button", { type: "button", className: "react-cupertino-ui-search-bar__cancel", onClick: handleCancel, tabIndex: showCancel ? 0 : -1, children: cancelLabel })] }), isFocused && suggestions.length > 0 && (_jsx("div", { className: "react-cupertino-ui-search-bar__suggestions", children: _jsx("ul", { className: "suggestions-list", children: suggestions.map((suggestion, index) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "suggestion-item", onMouseDown: (e) => {
44
+ e.preventDefault(); // Prevent blur
45
+ onSelectSuggestion?.(suggestion);
46
+ }, children: [_jsx(Search, { size: 14, className: "suggestion-icon" }), _jsx("span", { children: suggestion })] }) }, index))) }) }))] }));
47
+ });
48
+ SearchBar.displayName = "SearchBar";
49
+ export { SearchBar };
@@ -0,0 +1,191 @@
1
+ @use "@/styles/mixins/glass" as glass;
2
+
3
+ .react-cupertino-ui-search-bar {
4
+ position: relative;
5
+ width: 100%;
6
+ padding: 8px 16px;
7
+ z-index: 10;
8
+
9
+ &.glass {
10
+ // The container itself might not be glass, but the background behind it?
11
+ // Or typically SearchBar is transparent on a blurred NavigationBar.
12
+ // If it's standalone, it might have background.
13
+ // Let's assume transparent background by default, input is the glass element.
14
+ }
15
+
16
+ &__container {
17
+ display: flex;
18
+ align-items: center;
19
+ position: relative;
20
+ overflow: hidden; // For clipping the cancel button animation
21
+ }
22
+
23
+ &__input-wrapper {
24
+ flex: 1;
25
+ display: flex;
26
+ align-items: center;
27
+ height: 36px;
28
+ background: rgba(118, 118, 128, 0.12);
29
+ border-radius: 10px;
30
+ padding: 0 8px;
31
+ transition: background-color 0.2s ease;
32
+
33
+ @media (prefers-color-scheme: dark) {
34
+ background: rgba(118, 118, 128, 0.24);
35
+ }
36
+
37
+ &:focus-within {
38
+ background: rgba(118, 118, 128, 0.12); // Keep or change?
39
+ }
40
+
41
+ .search-icon {
42
+ color: var(--muted-foreground);
43
+ margin-right: 6px;
44
+ flex-shrink: 0;
45
+ }
46
+
47
+ .spinner {
48
+ width: 16px;
49
+ height: 16px;
50
+ border: 2px solid var(--muted-foreground);
51
+ border-top-color: transparent;
52
+ border-radius: 50%;
53
+ animation: spin 0.8s linear infinite;
54
+ }
55
+ }
56
+
57
+ &__input {
58
+ flex: 1;
59
+ border: none;
60
+ background: transparent;
61
+ height: 100%;
62
+ font-size: 17px;
63
+ color: var(--foreground);
64
+ min-width: 0;
65
+
66
+ &:focus {
67
+ outline: none;
68
+ }
69
+
70
+ &::placeholder {
71
+ color: var(--muted-foreground);
72
+ }
73
+ }
74
+
75
+ .clear-button {
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ width: 18px;
80
+ height: 18px;
81
+ border-radius: 50%;
82
+ background: var(--muted-foreground);
83
+ color: var(--background);
84
+ border: none;
85
+ padding: 0;
86
+ margin-left: 6px;
87
+ cursor: pointer;
88
+
89
+ svg {
90
+ display: block;
91
+ }
92
+ }
93
+
94
+ .voice-button {
95
+ background: transparent;
96
+ border: none;
97
+ color: var(--muted-foreground);
98
+ padding: 0;
99
+ margin-left: 6px;
100
+ cursor: pointer;
101
+ display: flex;
102
+ align-items: center;
103
+
104
+ &:hover {
105
+ color: var(--foreground);
106
+ }
107
+ }
108
+
109
+ &__cancel {
110
+ background: transparent;
111
+ border: none;
112
+ color: var(--color-blue);
113
+ font-size: 17px;
114
+ padding: 0 0 0 12px;
115
+ cursor: pointer;
116
+ white-space: nowrap;
117
+
118
+ // Animation logic
119
+ margin-right: -70px; // Hide by default
120
+ opacity: 0;
121
+ transition: margin-right 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
122
+ pointer-events: none;
123
+ }
124
+
125
+ &.is-focused {
126
+ .react-cupertino-ui-search-bar__cancel {
127
+ margin-right: 0;
128
+ opacity: 1;
129
+ pointer-events: auto;
130
+ }
131
+ }
132
+
133
+ &__suggestions {
134
+ position: absolute;
135
+ top: 100%;
136
+ left: 0;
137
+ right: 0;
138
+ background: var(--background);
139
+ @include glass.glass-panel(light, 20px, 0.95);
140
+ border-radius: 12px;
141
+ margin: 8px 16px;
142
+ padding: 8px 0;
143
+ box-shadow: 0 4px 20px rgba(0,0,0,0.1);
144
+
145
+ .suggestions-list {
146
+ list-style: none;
147
+ padding: 0;
148
+ margin: 0;
149
+ }
150
+
151
+ .suggestion-item {
152
+ display: flex;
153
+ align-items: center;
154
+ width: 100%;
155
+ padding: 10px 16px;
156
+ background: transparent;
157
+ border: none;
158
+ text-align: left;
159
+ font-size: 16px;
160
+ color: var(--foreground);
161
+ cursor: pointer;
162
+
163
+ .suggestion-icon {
164
+ margin-right: 12px;
165
+ color: var(--muted-foreground);
166
+ opacity: 0.7;
167
+ }
168
+
169
+ &:hover {
170
+ background: rgba(0,0,0,0.05);
171
+ }
172
+
173
+ // Separator except last
174
+ position: relative;
175
+ &:not(:last-child)::after {
176
+ content: '';
177
+ position: absolute;
178
+ bottom: 0;
179
+ left: 44px; // Align with text
180
+ right: 0;
181
+ height: 1px;
182
+ background: var(--border);
183
+ opacity: 0.5;
184
+ }
185
+ }
186
+ }
187
+ }
188
+
189
+ @keyframes spin {
190
+ to { transform: rotate(360deg); }
191
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@react-cupertino-ui/search-bar",
3
+ "version": "0.0.0",
4
+ "description": "SearchBar component from React Cupertino UI",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "sideEffects": [
13
+ "./dist/**/*.css",
14
+ "./dist/**/*.scss"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.build.json && npm run build:styles",
18
+ "build:styles": "node ../../../scripts/build-styles.mjs"
19
+ },
20
+ "peerDependencies": {
21
+ "react": "^18.3.1",
22
+ "react-dom": "^18.3.1"
23
+ },
24
+ "dependencies": {
25
+ "@react-cupertino-ui/shared": "0.0.0",
26
+ "lucide-react": "^0.417.0"
27
+ },
28
+ "devDependencies": {
29
+ "typescript": "^5.2.2"
30
+ },
31
+ "gitHead": "a6b07a7a8a0ab6f4c80884b6fb9d5eb16ee6da1d",
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }