Skip to content

Commit d3282a9

Browse files
authored
Feat: Strapi 5 support (#19)
* Feat: Strapi 5 support * Update readme
1 parent 0a6b20a commit d3282a9

21 files changed

Lines changed: 15505 additions & 3323 deletions

File tree

.babelrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
node_modules
1+
node_modules
2+
dist
3+
.yarn

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
<h1><strong>Tagsinput plugin for strapi with suggestions</strong></h1>
44

5+
<h3>🚀🚀🚀<strong>Use version <a href="https://github.com/canopas/strapi-plugin-tagsinput/releases/tag/2.0.0">2.0.0</a> for Strapi 5 support<strong>🚀🚀🚀<h3>
6+
57
This plugin is used to add tagsinput in your strapi admin panel.
68
Read more about it at [tagsinput guidence](https://blog.canopas.com/the-simple-guidance-how-to-add-tagsinput-customfield-plugin-in-strapi-b5d2b5af7c3b).
79

admin/jsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"jsx": "react",
5+
"module": "esnext",
6+
"allowSyntheticDefaultImports": true,
7+
"esModuleInterop": true
8+
},
9+
"include": ["./src/**/*.js", "./src/**/*.jsx"]
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useEffect, useRef } from 'react';
2+
import pluginId from "../pluginId";
3+
4+
/**
5+
* @type {import('react').FC<{ setPlugin: (id: string) => void }>}
6+
*/
7+
const Initializer = ({ setPlugin }) => {
8+
const ref = useRef(setPlugin);
9+
10+
useEffect(() => {
11+
ref.current(pluginId);
12+
}, []);
13+
14+
return null;
15+
};
16+
17+
export { Initializer };

admin/src/components/Initializer/index.js

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,10 @@ import TagsInput from "react-tagsinput";
22
import Autosuggest from "react-autosuggest";
33
import React, { useState, useRef, useEffect } from "react";
44
import PropTypes from "prop-types";
5-
import "../styles/global.css";
65
import axios from "axios";
7-
8-
import {
9-
Flex,
10-
Field,
11-
FieldHint,
12-
FieldError,
13-
FieldLabel,
14-
} from "@strapi/design-system";
6+
import { Flex, Field } from "@strapi/design-system";
157
import { useIntl } from "react-intl";
8+
import { css } from "./styles/global.ts";
169

1710
const Tags = ({
1811
attribute,
@@ -35,6 +28,8 @@ const Tags = ({
3528
}
3629
});
3730
const [suggestions, setSuggestions] = useState([]);
31+
const apiUrl = attribute?.options ? attribute.options["apiUrl"] : "";
32+
const attrName = apiUrl.slice(apiUrl.lastIndexOf('=') + 1);
3833
let inputEle = useRef(null);
3934

4035
useEffect(() => {
@@ -71,11 +66,11 @@ const Tags = ({
7166
};
7267

7368
const getSuggestions = async () => {
74-
if (!attribute.options || !attribute.options["apiUrl"]) {
69+
if (!apiUrl) {
7570
return [];
7671
}
7772
try {
78-
const res = await axios.get(attribute.options["apiUrl"]);
73+
const res = await axios.get(apiUrl);
7974
setSuggestions(res.data);
8075
} catch (err) {
8176
console.log(err);
@@ -100,19 +95,21 @@ const Tags = ({
10095
}
10196

10297
if (inputLength > 0) {
103-
s = s.map((state) => {
104-
const suggestionName = state.attributes
105-
? state.attributes.name.toLowerCase()
106-
: state.name.toLowerCase();
107-
108-
if (suggestionName.slice(0, inputLength) === inputValue) {
109-
return {
110-
id: state.id,
111-
name: suggestionName,
112-
};
113-
}
114-
return null
115-
}).filter((ele) => ele !== null || ele != undefined);
98+
s = s
99+
.map((state) => {
100+
const suggestionName = state.attributes
101+
? state.attributes[attrName].toLowerCase()
102+
: state[attrName].toLowerCase();
103+
104+
if (suggestionName.slice(0, inputLength) === inputValue) {
105+
return {
106+
id: state.id,
107+
name: suggestionName,
108+
};
109+
}
110+
return null;
111+
})
112+
.filter((ele) => ele !== null || ele != undefined);
116113
}
117114

118115
return (
@@ -133,36 +130,42 @@ const Tags = ({
133130
};
134131

135132
return (
136-
<Field
137-
name={name}
138-
id={name}
139-
// GenericInput calls formatMessage and returns a string for the error
140-
error={error}
141-
hint={description && formatMessage(description)}
142-
required={required}
143-
>
144-
<Flex
145-
direction="column"
146-
alignItems="stretch"
147-
gap={1}
148-
style={{
149-
position: `relative`,
150-
}}
151-
ref={inputEle}
133+
<>
134+
<style>{css}</style>
135+
<Field.Root
136+
name={name}
137+
id={name}
138+
// GenericInput calls formatMessage and returns a string for the error
139+
error={error}
140+
hint={description && formatMessage({ id: description })}
141+
required={required}
152142
>
153-
<FieldLabel action={labelAction}>{formatMessage(intlLabel)}</FieldLabel>
154-
<Flex direction="column">
155-
<TagsInput
156-
value={tags}
157-
onChange={handleTagsChange}
158-
onlyUnique={true}
159-
renderInput={autocompleteRenderInput}
160-
/>
143+
<Flex
144+
direction="column"
145+
alignItems="stretch"
146+
gap={1}
147+
style={{
148+
position: `relative`,
149+
}}
150+
ref={inputEle}
151+
>
152+
<Field.Label action={labelAction}>
153+
{intlLabel && formatMessage({ id: intlLabel })}
154+
</Field.Label>
155+
<Flex direction="column">
156+
<TagsInput
157+
classList={["test"]}
158+
value={tags}
159+
onChange={handleTagsChange}
160+
onlyUnique={true}
161+
renderInput={autocompleteRenderInput}
162+
/>
163+
</Flex>
164+
<Field.Hint />
165+
<Field.Error />
161166
</Flex>
162-
<FieldHint />
163-
<FieldError />
164-
</Flex>
165-
</Field>
167+
</Field.Root>
168+
</>
166169
);
167170
};
168171

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export const css = `
12
:root {
23
--primary: rgb(151, 54, 232);
34
--secondary: rgb(255, 255, 255);
@@ -84,7 +85,16 @@
8485
padding: 10px 20px;
8586
}
8687
88+
.react-autosuggest__suggestion > span {
89+
font-size: 13px;
90+
font-weight: 400;
91+
}
92+
8793
.react-autosuggest__suggestion--highlighted,
8894
.react-autosuggest__suggestion--focused {
8995
background-color: #ccc;
9096
}
97+
`
98+
99+
100+

admin/src/pages/App.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Page } from '@strapi/strapi/admin';
2+
import { Routes, Route } from 'react-router-dom';
3+
4+
import { HomePage } from './HomePage';
5+
6+
const App = () => {
7+
return (
8+
<Routes>
9+
<Route index element={<HomePage />} />
10+
<Route path="*" element={<Page.Error />} />
11+
</Routes>
12+
);
13+
};
14+
15+
export { App };

admin/src/pages/App/index.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)