Skip to content

Commit d8265f3

Browse files
Refactored TaxonomyTree into a separate component
1 parent 9033c54 commit d8265f3

File tree

6 files changed

+566
-471
lines changed

6 files changed

+566
-471
lines changed

docs/documentation/docs/controls/ModernTaxonomyPicker.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Custom rendering of a More actions button that displays a context menu for each
6868
customPanelWidth={700}
6969
isLightDismiss={false}
7070
isBlocking={false}
71-
onRenderActionButton={(termStoreInfo: ITermStoreInfo, termSetInfo: ITermSetInfo, termInfo?: ITermInfo) => {
71+
onRenderActionButton={(termStoreInfo: ITermStoreInfo, termSetInfo: ITermSetInfo, termInfo?: ITermInfo): JSX.Element => {
7272
const menuIcon: IIconProps = { iconName: 'MoreVertical', "aria-label": "More actions", style: { fontSize: "medium" } };
7373
if (termInfo) {
7474
const menuProps: IContextualMenuProps = {
@@ -147,4 +147,45 @@ The ModernTaxonomyPicker control can be configured with the following properties
147147
| isBlocking | boolean | no | Whether the panel uses a modal overlay or not. |
148148
| onRenderActionButton | function | no | Optional custom renderer for adding e.g. a button with additional actions to the terms in the tree view. |
149149

150-
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/TaxonomyPicker)
150+
## Standalone TaxonomyTree control
151+
152+
You can also use the `TaxonomyTree` control separately to just render a stand-alone tree-view of a term set with action buttons.
153+
154+
- Use the `TaxonomyTree` control in your code as follows:
155+
Initialize the taxonomy service and state, load basic info from term store and display the `TaxonomyTree` component.
156+
157+
```TypeScript
158+
const taxonomyService = new SPTaxonomyService(props.context);
159+
const [terms, setTerms] = React.useState<ITermInfo[]>();
160+
const [currentTermStoreInfo, setCurrentTermStoreInfo] = React.useState<ITermStoreInfo>();
161+
const [currentTermSetInfo, setCurrentTermSetInfo] = React.useState<ITermSetInfo>();
162+
const [currentLanguageTag, setCurrentLanguageTag] = React.useState<string>("");
163+
164+
React.useEffect(() => {
165+
sp.setup(props.context);
166+
taxonomyService.getTermStoreInfo()
167+
.then((termStoreInfo) => {
168+
setCurrentTermStoreInfo(termStoreInfo);
169+
setCurrentLanguageTag(props.context.pageContext.cultureInfo.currentUICultureName !== '' ?
170+
props.context.pageContext.cultureInfo.currentUICultureName :
171+
currentTermStoreInfo.defaultLanguageTag);
172+
});
173+
taxonomyService.getTermSetInfo(Guid.parse(props.termSetId))
174+
.then((termSetInfo) => {
175+
setCurrentTermSetInfo(termSetInfo);
176+
});
177+
}, []);
178+
179+
<TaxonomyTree
180+
languageTag={currentLanguageTag}
181+
onLoadMoreData={taxonomyService.getTerms}
182+
pageSize={50}
183+
setTerms={setTerms}
184+
termSetInfo={currentTermSetInfo}
185+
termStoreInfo={currentTermStoreInfo}
186+
terms={terms}
187+
onRenderActionButton={onRenderActionButton}
188+
/>
189+
```
190+
191+
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/ModernTaxonomyPicker)

src/controls/modernTaxonomyPicker/ModernTaxonomyPicker.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export interface IModernTaxonomyPickerProps {
6666
}
6767

6868
export function ModernTaxonomyPicker(props: IModernTaxonomyPickerProps) {
69-
const [taxonomyService] = React.useState(() => new SPTaxonomyService(props.context));
69+
const taxonomyService = new SPTaxonomyService(props.context);
7070
const [panelIsOpen, setPanelIsOpen] = React.useState(false);
7171
const [selectedOptions, setSelectedOptions] = React.useState<ITermInfo[]>([]);
7272
const [selectedPanelOptions, setSelectedPanelOptions] = React.useState<ITermInfo[]>([]);
@@ -265,8 +265,6 @@ export function ModernTaxonomyPicker(props: IModernTaxonomyPickerProps) {
265265
anchorTermInfo={currentAnchorTermInfo}
266266
termSetInfo={currentTermSetInfo}
267267
termStoreInfo={currentTermStoreInfo}
268-
context={props.context}
269-
termSetId={Guid.parse(props.termSetId)}
270268
pageSize={50}
271269
selectedPanelOptions={selectedPanelOptions}
272270
setSelectedPanelOptions={setSelectedPanelOptions}
Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
@import '~office-ui-fabric-react/dist/sass/References.scss';
22

33
.taxonomyPanelContents {
4-
.choiceOption {
5-
color: "[theme: bodyText, default: #323130]";
6-
display: inline-block;
7-
padding-inline-start: 26px;
8-
}
9-
10-
.disabledChoiceOption {
11-
color: "[theme: disabledBodyText, default: #323130]";
12-
display: inline-block;
13-
padding-inline-start: 26px;
14-
}
15-
16-
.selectedChoiceOption {
17-
font-weight: bold;
18-
}
19-
20-
.checkbox {
21-
color: "[theme: bodyText, default: #323130]";
22-
margin-inline-start: 4px;
23-
}
24-
25-
.disabledCheckbox {
26-
color: "[theme: disabledBodyText, default: #323130]";
27-
margin-inline-start: 4px;
28-
}
29-
30-
.selectedCheckbox {
31-
font-weight: bold;
32-
}
33-
344
.taxonomyTreeSelector {
355
border-bottom-color: blue;
366
border-bottom-style: solid;
@@ -42,35 +12,4 @@
4212
font-size: 18px;
4313
font-weight: 100;
4414
}
45-
46-
.spinnerContainer {
47-
height: 48px;
48-
line-height: 48px;
49-
display: flex;
50-
justify-content: center;
51-
align-items: center;
52-
}
53-
54-
.loadMoreContainer {
55-
height: 48px;
56-
line-height: 48px;
57-
}
58-
59-
.taxonomyItemFocusZone {
60-
display: flex;
61-
align-items: center;
62-
width: 100%;
63-
}
64-
65-
.taxonomyItemHeader {
66-
width: 100%;
67-
}
68-
69-
.taxonomyItemHeader .actionButtonContainer > * {
70-
opacity: 0;
71-
}
72-
73-
.taxonomyItemHeader:hover .actionButtonContainer > *, .taxonomyItemHeader:focus .actionButtonContainer > *, .taxonomyItemHeader .actionButtonContainer:focus-within > * {
74-
opacity: 1;
75-
}
7615
}

0 commit comments

Comments
 (0)