Skip to content

Commit f0e7aa1

Browse files
authored
Merge pull request #537 from joaojmendes/iconPickerNewViewOptions
New renderOption property on IconPicker
2 parents f8b4b4c + 50125ef commit f0e7aa1

File tree

9 files changed

+554
-9
lines changed

9 files changed

+554
-9
lines changed

config/serve.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://dev.office.com/json-schemas/core-build/serve.schema.json",
33
"port": 4321,
44
"initialPage": "https://localhost:5432/workbench",
5-
"https": true,
5+
"https": false,
66
"api": {
77
"port": 5432,
88
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
10.9 MB
Loading

docs/documentation/docs/controls/IconPicker.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Icon picker always opens a new panel where you can pick an icon. The panel displ
1212
![Icon Picker panel](../assets/IconPickerPanel.gif)
1313

1414

15+
## Displayed in the dialog
16+
Icon picker always opens a new dialog where you can pick an icon. The dialog displays all the icons and maintains readability. Picker does not displays selected icon outside the dialog.
17+
![Icon Picker panel](../assets/IconPicker_dialog.gif)
18+
1519
## How to use this control
1620

1721
- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../../#getting-started) page for more information about installing the dependency.
@@ -29,6 +33,13 @@ import { IconPicker } from '@pnp/spfx-controls-react/lib/IconPicker';
2933
onSave={(iconName: string) => { this.setState({icon: iconName}); }} />
3034
```
3135

36+
```TypeScript
37+
<IconPicker buttonLabel={'Icon'}
38+
renderOption={'Dialog'}
39+
onChange={(iconName: string) => { this.setState({icon: iconName}); }}
40+
onSave={(iconName: string) => { this.setState({icon: iconName}); }} />
41+
```
42+
3243
## Implementation
3344

3445
The IconPicker component can be configured with the following properties:
@@ -42,5 +53,6 @@ The IconPicker component can be configured with the following properties:
4253
| buttonClassName | boolean | no | If provided, additional class name will be added to the picker button |
4354
| panelClassName | boolean | no | If provided, additional class name will be added to the picker panel |
4455
| currentIcon | boolean | no | Specifies default selected icon |
56+
| renderOption | string | no | Specifies how to render list of Icons, Values : 'Panel' or 'Dialog' defualt value 'Panel' |
4557

4658
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/IconPicker)

src/controls/iconPicker/IIconPickerProps.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ export interface IIconPickerProps {
2727
* initially selected icon
2828
*/
2929
currentIcon?: string;
30-
}
30+
/**
31+
* irender option: Panel, Dialog, dropDown
32+
*/
33+
renderOption?: string;
34+
}

src/controls/iconPicker/IconPicker.module.scss

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
@import '~office-ui-fabric-react/dist/sass/References.scss';
22

3+
.dialogSelectedIcons{
4+
font-size: 30px;
5+
min-width: 32px;
6+
width: 100%;
7+
color: "[theme: themePrimary, default: #0078d7]";
8+
text-align: center;
9+
}
10+
.dialogIconsContainer{
11+
padding:5px;
12+
overflow: auto;
13+
max-height: 600px;
14+
}
315
.navArea {
416
display: flex;
517
width: 100%;
@@ -17,7 +29,7 @@
1729
.searchBox {
1830
flex-grow: 5;
1931
flex-shrink: 1;
20-
margin: 5px 0;
32+
margin: 5px 0;
2133
}
2234
.closeBtnContainer {
2335
flex: 0 0 54px;
@@ -85,7 +97,7 @@
8597
color: "[theme: themePrimary, default: #0078d7]";
8698
}
8799
.iconRadio:focus + .iconLabel {
88-
outline: 1px dashed;
100+
outline: 1px;
89101
outline-color: "[theme: themePrimary, default: #0078d7]";
90102
outline-offset: -5px;
91103
}
@@ -135,4 +147,4 @@
135147
}
136148
.btnSave {
137149
order: 3;
138-
}
150+
}

src/controls/iconPicker/IconPicker.tsx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import { Panel, PanelType, IPanelProps } from 'office-ui-fabric-react/lib/Panel'
1111
import { debounce } from 'lodash';
1212
import { IIconPickerState } from './IIconPickerState';
1313
import * as telemetry from '../../common/telemetry';
14+
import {Dialog, DialogType, DialogFooter } from 'office-ui-fabric-react/lib/Dialog';
15+
import { initializeIcons } from 'office-ui-fabric-react/lib/Icons';
1416

17+
initializeIcons();
1518

1619
export class IconPicker extends React.Component<IIconPickerProps, IIconPickerState> {
1720
private radioIdBase: string = getId("radio");
1821

22+
1923
constructor(props: IIconPickerProps) {
2024
super(props);
2125

@@ -29,6 +33,8 @@ export class IconPicker extends React.Component<IIconPickerProps, IIconPickerSta
2933
}
3034

3135
public render(): React.ReactElement<IIconPickerProps> {
36+
let { renderOption} = this.props;
37+
renderOption = renderOption === undefined ? 'Panel' : renderOption.toLowerCase() === 'dialog' ? 'Dialog' : 'Panel';
3238
return <div>
3339
<PrimaryButton
3440
text={this.props.buttonLabel}
@@ -37,6 +43,9 @@ export class IconPicker extends React.Component<IIconPickerProps, IIconPickerSta
3743
disabled={this.props.disabled}
3844
data-automation-id={`icon-picker-open`}
3945
/>
46+
{
47+
48+
renderOption == 'Panel' ?
4049
<Panel
4150
isOpen={this.state.isPanelOpen}
4251
onDismiss={this.closePanel}
@@ -49,6 +58,38 @@ export class IconPicker extends React.Component<IIconPickerProps, IIconPickerSta
4958
>
5059
{this.renderPanelContent()}
5160
</Panel>
61+
:
62+
<Dialog
63+
hidden={!this.state.isPanelOpen}
64+
onDismiss={this.closePanel}
65+
isBlocking={true}
66+
67+
dialogContentProps={{
68+
type: DialogType.normal,
69+
title: strings.SelectIcon,
70+
showCloseButton: true,
71+
72+
}}
73+
>
74+
<SearchBox className={styles.searchBox}
75+
onAbort={this.onAbort}
76+
data-automation-id={`icon-picker-search`}
77+
78+
onChange={this.onChange} />
79+
<div className={styles.dialogIconsContainer}>
80+
{this.renderPanelContent()}
81+
</div>
82+
83+
<DialogFooter>
84+
<div style={{display:'flex', flexDirection: 'row' , justifyContent:'flex-end', }}>
85+
<Icon iconName={this.state.currentIcon} className={styles.dialogSelectedIcons}/>
86+
<PrimaryButton style={{marginRight: 5}} text={strings.SaveButtonLabel} onClick={this.confirmSelection} disabled={!this.state.currentIcon} data-automation-id={`icon-picker-save`} />
87+
<DefaultButton text={strings.CancelButtonLabel} onClick={this.closePanel} className={styles.btnCancel} data-automation-id={`icon-picker-close`} />
88+
</div>
89+
</DialogFooter>
90+
</Dialog>
91+
92+
}
5293
</div>;
5394
}
5495

@@ -61,12 +102,14 @@ export class IconPicker extends React.Component<IIconPickerProps, IIconPickerSta
61102

62103
private iconPickerOnClick = (): void => {
63104
this.setState({
64-
isPanelOpen: true
105+
isPanelOpen: true,
106+
items :IconNames.Icons
65107
});
66108
}
67109

68110
private iconOnClick = (iconName: string): void => {
69111
if (this.props.onChange) this.props.onChange(iconName);
112+
console.log(iconName);
70113
this.setState({
71114
currentIcon: iconName,
72115
});

src/webparts/controlsTest/ControlsTestWebPart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@microsoft/sp-webpart-base';
99

1010
import * as strings from 'ControlsTestWebPartStrings';
11-
import ControlsTest from './components/ControlsTest';
11+
import ControlsTest from './components/ControlsTest_SingleComponent';
1212
import { IControlsTestProps } from './components/IControlsTestProps';
1313
import { IControlsTestWebPartProps } from './IControlsTestWebPartProps';
1414

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,8 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
808808
onSelectedItem={this.listItemPickerDataSelected} />
809809

810810
</div>
811-
<div>Icon Picker</div>
812-
<div><IconPicker onSave={(value) => { console.log(value); }} buttonLabel="Icon Picker"></IconPicker></div>
811+
<div>Icon Picker</div>
812+
<div><IconPicker renderOption="dialog" onSave={(value)=>{console.log(value);}} buttonLabel="Icon Picker"></IconPicker></div>
813813

814814
<div className="ms-font-m">ComboBoxListItemPicker:
815815

0 commit comments

Comments
 (0)