Skip to content

Commit f60eb70

Browse files
committed
custom render + searchbox
1 parent febe234 commit f60eb70

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/common/utilities/GeneralHelper.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,12 @@ export function urlCombine(urlStart: string, urlFinish: string, escapeFinish: bo
351351

352352
return url;
353353
}
354+
355+
export const toRelativeUrl = (absoluteUrl: string): string => {
356+
357+
if (!absoluteUrl) {
358+
return '';
359+
}
360+
361+
return absoluteUrl.replace(/^(?:\/\/|[^/]+)*\//, '/');
362+
};

src/controls/sitePicker/SitePicker.tsx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,43 @@ import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/Spinner';
44
import { ISite, ISitePickerProps } from './ISitePicker';
55
import { getAllSites, getHubSites } from '../../services/SPSitesService';
66
import { IDropdownOption, Dropdown } from 'office-ui-fabric-react/lib/Dropdown';
7-
import { SelectableOptionMenuItemType } from 'office-ui-fabric-react/lib/utilities/selectableOption/SelectableOption.types';
7+
import { ISelectableOption, SelectableOptionMenuItemType } from 'office-ui-fabric-react/lib/utilities/selectableOption/SelectableOption.types';
88
import orderBy from 'lodash/orderBy';
9+
import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox';
10+
import { Checkbox } from 'office-ui-fabric-react/lib/Checkbox';
11+
import { toRelativeUrl } from '../../common/utilities/GeneralHelper';
912

1013
const styles = mergeStyleSets({
1114
loadingSpinnerContainer: {
1215
width: '100%',
1316
textAlign: 'center'
17+
},
18+
siteOption: {
19+
display: 'flex',
20+
whiteSpace: 'nowrap',
21+
alignItems: 'center'
22+
},
23+
siteOptionCheckbox: {
24+
display: 'inline-block',
25+
marginRight: '4px'
26+
},
27+
siteOptionContent: {
28+
display: 'flex',
29+
flexDirection: 'column',
30+
minWidth: '0',
31+
padding: '4px 0'
32+
},
33+
siteOptionTitle: {
34+
lineHeight: '18px',
35+
overflow: 'hidden',
36+
textOverflow: 'ellipsis'
37+
},
38+
siteOptionUrl: {
39+
fontSize: '12px',
40+
lineHeight: '14px',
41+
fontWeight: '300',
42+
overflow: 'hidden',
43+
textOverflow: 'ellipsis'
1444
}
1545
});
1646

@@ -36,6 +66,23 @@ export const SitePicker: React.FunctionComponent<ISitePickerProps> = (props: Rea
3666
const [filteredSites, setFilteredSites] = React.useState<ISite[]>();
3767
const [searchQuery, setSearchQuery] = React.useState<string>();
3868

69+
const onRenderOption = (option?: ISelectableOption, defaultRender?: (props?: ISelectableOption) => JSX.Element | null): JSX.Element | null => {
70+
if (!props) {
71+
return null;
72+
}
73+
74+
if (option.itemType === SelectableOptionMenuItemType.Header) {
75+
return <SearchBox />;
76+
}
77+
// {multiSelect !== false && <Checkbox className={styles.siteOptionCheckbox} checked={option.selected} disabled={option.disabled} />}
78+
return <div className={styles.siteOption}>
79+
<div className={styles.siteOptionContent}>
80+
<span className={styles.siteOptionTitle}>{option.text}</span>
81+
<span className={styles.siteOptionUrl}>{toRelativeUrl(option.data!.url)}</span>
82+
</div>
83+
</div>;
84+
};
85+
3986
const getOptions = (): IDropdownOption[] => {
4087
const result: IDropdownOption[] = [];
4188

@@ -132,6 +179,7 @@ export const SitePicker: React.FunctionComponent<ISitePickerProps> = (props: Rea
132179
options={getOptions()}
133180
disabled={disabled}
134181
multiSelect={multiSelect !== false}
182+
onRenderOption={onRenderOption}
135183
/>
136184
</>
137185
);

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
13171317
label={'select sites'}
13181318
mode={'web'}
13191319
allowSearch={true}
1320+
multiSelect={true}
13201321
onChange={() => {}} />
13211322
</div>
13221323

0 commit comments

Comments
 (0)