|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +import React, { useCallback } from 'react'; |
| 11 | +import { EuiBadge, EuiToolTip } from '@elastic/eui'; |
| 12 | +import { css } from '@emotion/react'; |
| 13 | +import type { FeatureFlagsStart } from '@kbn/core-feature-flags-browser'; |
| 14 | +import { isNextChrome, toggleNextChrome } from '.'; |
| 15 | + |
| 16 | +const badgeStyles = css` |
| 17 | + cursor: pointer; |
| 18 | +`; |
| 19 | + |
| 20 | +interface ChromeNextToggleProps { |
| 21 | + featureFlags: Pick<FeatureFlagsStart, 'getBooleanValue'>; |
| 22 | +} |
| 23 | + |
| 24 | +export const ChromeNextToggle: React.FC<ChromeNextToggleProps> = ({ featureFlags }) => { |
| 25 | + const isEnabled = isNextChrome(featureFlags); |
| 26 | + |
| 27 | + const onClick = useCallback(() => { |
| 28 | + toggleNextChrome(featureFlags); |
| 29 | + }, [featureFlags]); |
| 30 | + |
| 31 | + return ( |
| 32 | + <EuiToolTip |
| 33 | + content={`Click to ${isEnabled ? 'disable' : 'enable'} Chrome Next. Page will reload.`} |
| 34 | + > |
| 35 | + <EuiBadge |
| 36 | + color={isEnabled ? 'success' : 'danger'} |
| 37 | + css={badgeStyles} |
| 38 | + iconType="beaker" |
| 39 | + iconSide="left" |
| 40 | + onClick={onClick} |
| 41 | + onClickAriaLabel="Toggle Chrome Next" |
| 42 | + > |
| 43 | + Chrome Next: {isEnabled ? 'ON' : 'OFF'} |
| 44 | + </EuiBadge> |
| 45 | + </EuiToolTip> |
| 46 | + ); |
| 47 | +}; |
0 commit comments