|
| 1 | +import React from "react"; |
| 2 | +import ReactDOM from "react-dom/client"; |
| 3 | +import "./index.css"; |
| 4 | +import "./layout.css"; |
| 5 | +import { IgrTileManager, IgrTile, IgrIconButton, registerIconFromText } from "igniteui-react"; |
| 6 | +import "igniteui-webcomponents/themes/light/bootstrap.css"; |
| 7 | + |
| 8 | +export default class Actions extends React.Component<any, any> { |
| 9 | + |
| 10 | + constructor(props: any) { |
| 11 | + super(props); |
| 12 | + const northEast = |
| 13 | + '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#5f6368"><path d="m216-160-56-56 464-464H360v-80h400v400h-80v-264L216-160Z"/></svg>'; |
| 14 | + registerIconFromText('north_east', northEast, 'material'); |
| 15 | + const southWest = |
| 16 | + '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#5f6368"><path d="M200-200v-400h80v264l464-464 56 56-464 464h264v80H200Z"/></svg>'; |
| 17 | + registerIconFromText('south_west', southWest, 'material'); |
| 18 | + const more = |
| 19 | + '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#5f6368"><path d="M480-160q-33 0-56.5-23.5T400-240q0-33 23.5-56.5T480-320q33 0 56.5 23.5T560-240q0 33-23.5 56.5T480-160Zm0-240q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Zm0-240q-33 0-56.5-23.5T400-720q0-33 23.5-56.5T480-800q33 0 56.5 23.5T560-720q0 33-23.5 56.5T480-640Z"/></svg>'; |
| 20 | + registerIconFromText('more', more, 'material'); |
| 21 | + const chart = |
| 22 | + '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#5f6368"><path d="M640-160v-280h160v280H640Zm-240 0v-640h160v640H400Zm-240 0v-440h160v440H160Z"/></svg>'; |
| 23 | + registerIconFromText('chart', chart, 'material'); |
| 24 | + } |
| 25 | + |
| 26 | + private onCustomOneClick = (event: React.MouseEvent) => { |
| 27 | + |
| 28 | + const tile = (event.currentTarget as HTMLElement).closest('igc-tile'); |
| 29 | + |
| 30 | + if (tile) { |
| 31 | + tile.maximized = !tile.maximized; |
| 32 | + |
| 33 | + const actionsSlot = tile.querySelector('[slot="actions"]') as HTMLElement; |
| 34 | + const currentBtn = event.currentTarget as HTMLElement; |
| 35 | + |
| 36 | + if (currentBtn) { |
| 37 | + if ( |
| 38 | + tile.maximized |
| 39 | + ) { |
| 40 | + currentBtn.setAttribute('name', 'south_west'); |
| 41 | + currentBtn.setAttribute('aria-label', 'collapse'); |
| 42 | + |
| 43 | + const chartBtn = document.createElement('igc-icon-button'); |
| 44 | + chartBtn.classList.add('additional-action'); |
| 45 | + chartBtn.setAttribute('slot', 'actions'); |
| 46 | + chartBtn.setAttribute('variant', 'flat'); |
| 47 | + chartBtn.setAttribute('collection', 'material'); |
| 48 | + chartBtn.setAttribute('name', 'chart'); |
| 49 | + chartBtn.setAttribute('aria-label', 'chart'); |
| 50 | + |
| 51 | + const moreBtn = document.createElement('igc-icon-button'); |
| 52 | + moreBtn.classList.add('additional-action'); |
| 53 | + moreBtn.setAttribute('slot', 'actions'); |
| 54 | + moreBtn.setAttribute('variant', 'flat'); |
| 55 | + moreBtn.setAttribute('collection', 'material'); |
| 56 | + moreBtn.setAttribute('name', 'more'); |
| 57 | + moreBtn.setAttribute('aria-label', 'more'); |
| 58 | + |
| 59 | + tile.append(chartBtn); |
| 60 | + tile.append(moreBtn); |
| 61 | + } else { |
| 62 | + currentBtn.setAttribute('name', 'north_east'); |
| 63 | + currentBtn.setAttribute('aria-label', 'expand'); |
| 64 | + |
| 65 | + const additionalButtons = |
| 66 | + actionsSlot.parentElement?.querySelectorAll('.additional-action'); |
| 67 | + additionalButtons?.forEach((btn) => btn.remove()); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + }; |
| 72 | + |
| 73 | + private onCustomTwoClick = (event: React.MouseEvent) => { |
| 74 | + const tile = (event.currentTarget as HTMLElement).closest('igc-tile'); |
| 75 | + |
| 76 | + if (tile) { |
| 77 | + tile.maximized = !tile.maximized; |
| 78 | + |
| 79 | + const currentBtn = event.currentTarget as HTMLElement; |
| 80 | + |
| 81 | + if (currentBtn) { |
| 82 | + if ( |
| 83 | + tile.maximized |
| 84 | + ) { |
| 85 | + currentBtn.setAttribute('name', 'south_west'); |
| 86 | + currentBtn.setAttribute('aria-label', 'collapse'); |
| 87 | + } |
| 88 | + else { |
| 89 | + currentBtn.setAttribute('name', 'north_east'); |
| 90 | + currentBtn.setAttribute('aria-label', 'expand'); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + }; |
| 95 | + |
| 96 | + public render(): JSX.Element { |
| 97 | + return ( |
| 98 | + <div className="container sample center"> |
| 99 | + <IgrTileManager id="tile-manager1" columnCount={2} gap="20px"> |
| 100 | + <IgrTile> |
| 101 | + <h3 slot="title">Default Actions</h3> |
| 102 | + <p>This tile has default actions and title.</p> |
| 103 | + </IgrTile> |
| 104 | + <IgrTile disableFullscreen> |
| 105 | + <h3 slot="title">No Fullscreen Action</h3> |
| 106 | + <p>Fullscreen is disabled via property.</p> |
| 107 | + </IgrTile> |
| 108 | + <IgrTile disableFullscreen disableMaximize> |
| 109 | + <h3 slot="title">Custom Actions</h3> |
| 110 | + <IgrIconButton id="customOne" onClick={this.onCustomOneClick} slot="actions" variant="flat" collection="material" name="north_east" |
| 111 | + aria-label="north_east"></IgrIconButton> |
| 112 | + <p>Replace the default actions with custom ones, and include extra actions when the tile is maximized.</p> |
| 113 | + </IgrTile> |
| 114 | + <IgrTile disableFullscreen disableMaximize> |
| 115 | + <IgrIconButton id="customTwo" onClick={this.onCustomTwoClick} slot="actions" variant="flat" collection="material" |
| 116 | + name="north_east" aria-label="north_east"></IgrIconButton> |
| 117 | + <p>Display only custom actions in the header.</p> |
| 118 | + </IgrTile> |
| 119 | + <IgrTile disableFullscreen disableMaximize> |
| 120 | + <h3 slot="title">Only title</h3> |
| 121 | + <p>Display only title in the header.</p> |
| 122 | + </IgrTile> |
| 123 | + <IgrTile disableFullscreen disableMaximize> |
| 124 | + <p>Content only.</p> |
| 125 | + </IgrTile> |
| 126 | + </IgrTileManager> |
| 127 | + </div> |
| 128 | + ); |
| 129 | + } |
| 130 | + |
| 131 | +} |
| 132 | + |
| 133 | +// rendering above class to the React DOM |
| 134 | +const root = ReactDOM.createRoot(document.getElementById("root")); |
| 135 | +root.render(<Actions/>); |
0 commit comments