Skip to content

Commit cdd2328

Browse files
committed
try to extract css to a separate exported file
1 parent 93bae3b commit cdd2328

File tree

8 files changed

+148
-115
lines changed

8 files changed

+148
-115
lines changed

.npmignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Do not ignore dist for npm pack
2+
# (npm will use this file instead of .gitignore)
3+
# Add any files you want to exclude from npm package below
4+
5+
# Example: exclude tests and config files
6+
*.test.*
7+
*.spec.*
8+
.vscode/
9+
node_modules/
10+
11+
# Do NOT ignore dist
12+
# dist/

global.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.css' {
2+
const content: { [className: string]: string };
3+
export default content;
4+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.opwp-block {
2+
padding: 12px 10px;
3+
border: none;
4+
border-radius: 5px;
5+
background-color: #FBF5F2;
6+
width: 450px;
7+
}
8+
9+
.opwp-search-container {
10+
position: relative;
11+
}
12+
13+
.opwp-search-input {
14+
width: 100%;
15+
padding: 8px 12px;
16+
border-radius: 4px;
17+
border: 1px solid #ccc;
18+
font-size: 14px;
19+
}
20+
21+
.opwp-dropdown {
22+
position: absolute;
23+
top: 100%;
24+
left: 0;
25+
right: 0;
26+
z-index: 10;
27+
background-color: white;
28+
border: 1px solid #ccc;
29+
border-radius: 0 0 4px 4px;
30+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
31+
max-height: 200px;
32+
overflow-y: auto;
33+
margin-top: 2px;
34+
}
35+
36+
.opwp-dropdown-option {
37+
padding: 8px 12px;
38+
cursor: pointer;
39+
background-color: transparent;
40+
border-bottom: 1px solid #eee;
41+
}
42+
43+
.opwp-dropdown-option.selected {
44+
background-color: #f0f0f0;
45+
}
46+
47+
.opwp-type {
48+
gap: 8px;
49+
font-weight: bold;
50+
text-transform: uppercase;
51+
}
52+
53+
.opwp-type-color {
54+
color: var(--opwp-type-color, #000091);
55+
}
56+
57+
.opwp-id {
58+
color: #666;
59+
}
60+
61+
.opwp-status {
62+
font-size: 0.8rem;
63+
border-radius: 12px;
64+
padding: 2px 8px;
65+
border: 1px solid #ccc;
66+
background-color: var(--opwp-status-color, #000091);
67+
}
68+
69+
.opwp-link {
70+
margin-right: 6px;
71+
text-decoration: none;
72+
color: #000091;
73+
cursor: pointer;
74+
}

lib/components/OpenProjectWorkPackageBlock.tsx

Lines changed: 48 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { useWorkPackageSearch } from "../hooks/useWorkPackageSearch";
66
import type { WorkPackage } from "../openProjectTypes";
77
import { linkToWorkPackage } from "../services/openProjectApi";
88

9+
import "./OpenProjectWorkPackageBlock.css";
10+
911
const UI_BLUE = "#000091"; // Default color for task status icons
10-
const UI_BEIGE = "#FBF5F2";
1112

1213
interface BlockProps {
1314
props: {
@@ -35,8 +36,6 @@ const OpenProjectWorkPackageBlockComponent = ({
3536
searchQuery,
3637
setSearchQuery,
3738
searchResults,
38-
// loading: searchLoading,
39-
// error: searchError,
4039
} = useWorkPackageSearch();
4140

4241
const [selectedWorkPackage, setSelectedWorkPackage] = useState<WorkPackage | null>(null);
@@ -45,12 +44,20 @@ const OpenProjectWorkPackageBlockComponent = ({
4544

4645
// Load saved work package if it exists
4746
const workPackageResult = useWorkPackage(block.props.wpid);
48-
if (!workPackageResult.error && workPackageResult.workPackage) {
49-
setSelectedWorkPackage(workPackageResult.workPackage);
50-
} else {
51-
// Autofocus search
52-
setTimeout(() => inputRef?.current?.focus(), 50);
53-
}
47+
48+
// Set selected work package when loaded
49+
useEffect(() => {
50+
if (!workPackageResult.error && workPackageResult.workPackage) {
51+
setSelectedWorkPackage(workPackageResult.workPackage);
52+
}
53+
}, [workPackageResult.error, workPackageResult.workPackage]);
54+
55+
// Autofocus search if no work package
56+
useEffect(() => {
57+
if (workPackageResult.error || !workPackageResult.workPackage) {
58+
setTimeout(() => inputRef?.current?.focus(), 50);
59+
}
60+
}, [workPackageResult.error, workPackageResult.workPackage]);
5461

5562
// Handle click outside to close dropdown
5663
useEffect(() => {
@@ -121,80 +128,45 @@ const OpenProjectWorkPackageBlockComponent = ({
121128
};
122129

123130
return (
124-
<div
125-
style={{
126-
padding: "12px 10px",
127-
border: "none",
128-
borderRadius: "5px",
129-
backgroundColor: UI_BEIGE,
130-
width: "450px",
131-
}}
132-
>
131+
<div className="opwp-block">
133132
<div>
134133
{!block.props.wpid && (
135-
<div style={{ position: "relative" }}>
136-
<div
137-
style={{
138-
display: "flex",
134+
<div className="opwp-search-container">
135+
<input
136+
ref={inputRef}
137+
type="text"
138+
className="opwp-search-input"
139+
placeholder={"Search for work package ID or subject"}
140+
value={searchQuery}
141+
onChange={(e) => {
142+
setSearchQuery(e.target.value);
143+
if (e.target.value) {
144+
setIsDropdownOpen(true);
145+
}
139146
}}
140-
>
141-
<input
142-
ref={inputRef}
143-
type="text"
144-
placeholder={"Search for work package ID or subject"}
145-
value={searchQuery}
146-
onChange={(e) => {
147-
setSearchQuery(e.target.value);
148-
if (e.target.value) {
149-
setIsDropdownOpen(true);
150-
}
151-
}}
152-
onFocus={() => {
153-
if (searchResults.length > 0) {
154-
setIsDropdownOpen(true);
155-
}
156-
}}
157-
onKeyDown={handleKeyDown}
158-
style={{
159-
width: "100%",
160-
padding: "8px 12px",
161-
borderRadius: "4px",
162-
border: "1px solid #ccc",
163-
fontSize: "14px",
164-
}}
165-
/>
166-
{/* <button onClick={() => setMode('create')}>
167-
{t('New Work Package')}
168-
</button> */}
169-
</div>
147+
onFocus={() => {
148+
if (searchResults.length > 0) {
149+
setIsDropdownOpen(true);
150+
}
151+
}}
152+
onKeyDown={handleKeyDown}
153+
/>
170154

171155
{/* Autocomplete dropdown */}
172156
{isDropdownOpen && searchResults.length > 0 && (
173157
<div
174158
ref={dropdownRef}
175159
role="listbox"
176160
aria-label={"Work package search results"}
177-
style={{
178-
position: "absolute",
179-
top: "100%",
180-
left: 0,
181-
right: 0,
182-
zIndex: 10,
183-
backgroundColor: "white",
184-
border: "1px solid #ccc",
185-
borderRadius: "0 0 4px 4px",
186-
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
187-
maxHeight: "200px",
188-
overflowY: "auto",
189-
marginTop: "2px",
190-
}}
161+
className="opwp-dropdown"
191162
>
192163
{searchResults.slice(0, 5).map((wp, index) => (
193164
<div
194165
key={wp.id}
195166
role="option"
196167
aria-selected={focusedResultIndex === index}
197168
tabIndex={0}
169+
className={`opwp-dropdown-option${focusedResultIndex === index ? " selected" : ""}`}
198170
onClick={() => handleSelectWorkPackage(wp)}
199171
onKeyDown={(e) => {
200172
if (e.key === "Enter" || e.key === " ") {
@@ -203,12 +175,6 @@ const OpenProjectWorkPackageBlockComponent = ({
203175
}
204176
}}
205177
onMouseEnter={() => setFocusedResultIndex(index)}
206-
style={{
207-
padding: "8px 12px",
208-
cursor: "pointer",
209-
backgroundColor: focusedResultIndex === index ? "#f0f0f0" : "transparent",
210-
borderBottom: index < searchResults.length - 1 ? "1px solid #eee" : "none",
211-
}}
212178
>
213179
<div style={{ fontWeight: "bold" }}>
214180
#{wp.id} - {wp.subject}
@@ -222,57 +188,30 @@ const OpenProjectWorkPackageBlockComponent = ({
222188
)}
223189
</div>
224190
)}
225-
{block.props.wpid && !selectedWorkPackage && (
226-
<div>
227-
#{block.props.wpid} {block.props.subject}
228-
</div>
229-
)}
230191
{/* Display selected work package details */}
231192
{selectedWorkPackage && (
232193
<div>
233-
<div
234-
style={{
235-
display: "flex",
236-
gap: "8px",
237-
}}
238-
>
194+
<div style={{ display: "flex", gap: "8px" }}>
239195
<div
240-
style={{
241-
gap: "8px",
242-
color: selectedWorkPackage._embedded?.type?.color || UI_BLUE,
243-
fontWeight: "bold",
244-
textTransform: "uppercase",
245-
}}
196+
className="opwp-type opwp-type-color"
197+
style={{ color: selectedWorkPackage._embedded?.type?.color || UI_BLUE }}
246198
>
247199
{selectedWorkPackage._links?.type?.title}
248200
</div>
201+
<div className="opwp-id">#{selectedWorkPackage.id}</div>
249202
<div
250-
style={{
251-
color: "#666",
252-
}}
253-
>
254-
#{selectedWorkPackage.id}
255-
</div>
256-
<div
257-
style={{
258-
fontSize: "0.8rem",
259-
borderRadius: "12px",
260-
padding: "2px 8px",
261-
border: "1px solid #ccc",
262-
backgroundColor: selectedWorkPackage._embedded?.status?.color || UI_BLUE,
263-
}}
203+
className="opwp-status"
204+
style={{ backgroundColor: selectedWorkPackage._embedded?.status?.color || UI_BLUE }}
264205
>
265206
{selectedWorkPackage._links?.status?.title}
266207
</div>
267208
</div>
268209

269210
<div>
270-
<a href={linkToWorkPackage(block.props.wpid)} style={{
271-
marginRight: 6,
272-
textDecoration: "none",
273-
color: UI_BLUE,
274-
cursor: "pointer",
275-
}} >
211+
<a
212+
href={linkToWorkPackage(block.props.wpid)}
213+
className="opwp-link"
214+
>
276215
{selectedWorkPackage.subject}
277216
</a>
278217
</div>

lib/hooks/useWorkPackage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ export function useWorkPackage(wpid: string | null) {
3535
fetchWorkPackage();
3636
}, [fetchWorkPackage]);
3737

38-
return { workPackage, loading, error, refetch: fetchWorkPackage };
39-
}
38+
return { workPackage, loading, error };
39+
}

lib/hooks/useWorkPackageSearch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function useWorkPackageSearch(
2626

2727
setLoading(true);
2828
setError(null);
29-
const timer = setTimeout(() => {
29+
const debouncedSearchQuery = setTimeout(() => {
3030
searchWorkPackages(searchQuery)
3131
.then((results) => {
3232
setSearchResults(results);
@@ -40,7 +40,7 @@ export function useWorkPackageSearch(
4040
});
4141
}, debounce);
4242

43-
return () => clearTimeout(timer);
43+
return () => clearTimeout(debouncedSearchQuery);
4444
}, [searchQuery, debounce]);
4545

4646
return {

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"type": "module",
66
"module": "dist/op-blocknote-extensions.es.js",
77
"types": "dist/index.d.ts",
8+
"files": [
9+
"dist"
10+
],
11+
"style": "dist/op-blocknote-extensions.css",
812
"scripts": {
913
"dev": "vite",
1014
"build": "tsc -b && vite build",
@@ -33,4 +37,4 @@
3337
"react": "^19.1.0",
3438
"react-dom": "^19.1.0"
3539
}
36-
}
40+
}

tsconfig.lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"noEmit": false,
99
"strict": true,
1010
},
11-
"include": ["lib/**/*.ts", "lib/**/*.tsx"]
11+
"include": ["lib/**/*.ts", "lib/**/*.tsx", "*.d.ts"]
1212
}

0 commit comments

Comments
 (0)