PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.2
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / components / responsive-tab-panel / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.2, at gutenberg/components/responsive-tab-panel/index.js

82 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import classnames from 'classnames/dedupe';
2
3 import { Button, Tooltip } from '@wordpress/components';
4 import { __, sprintf } from '@wordpress/i18n';
5
6 import useResponsive from '../../hooks/use-responsive';
7 import getIcon from '../../utils/get-icon';
8 import ActiveIndicator from '../active-indicator';
9
10 /**
11 * Component Class
12 *
13 * @param props
14 */
15 export default function ResponsiveTabPanel(props) {
16 const { children } = props;
17
18 // Fallback for deprecated filledTabs prop.
19 const active = props?.active || props?.filledTabs || {};
20
21 const { allDevices, device, setDevice } = useResponsive();
22
23 const tabs = [];
24 const icons = [
25 getIcon('tabs-mobile'),
26 getIcon('tabs-tablet'),
27 getIcon('tabs-laptop'),
28 getIcon('tabs-desktop'),
29 getIcon('tabs-tv'),
30 ];
31
32 [...Object.keys(allDevices), ''].forEach((name, i) => {
33 tabs.unshift({
34 name,
35 title: (
36 <Tooltip
37 text={
38 !name
39 ? __('All devices', 'ghostkit')
40 : sprintf(
41 __(
42 'Devices with screen width <= %s',
43 'ghostkit'
44 ),
45 `${allDevices[name]}px`
46 )
47 }
48 >
49 <span className="ghostkit-control-tabs-icon">
50 {icons[i]}
51 {active && active[name] ? <ActiveIndicator /> : ''}
52 </span>
53 </Tooltip>
54 ),
55 });
56 });
57
58 return (
59 <div className="ghostkit-control-tabs ghostkit-control-tabs-wide">
60 <div className="components-tab-panel__tabs">
61 {tabs.map((data) => {
62 return (
63 <Button
64 key={data.name}
65 className={classnames(
66 'ghostkit-control-tabs-tab',
67 data.name === device && 'is-active'
68 )}
69 onClick={() => {
70 setDevice(data.name);
71 }}
72 >
73 {data.title}
74 </Button>
75 );
76 })}
77 </div>
78 {children({ name: device })}
79 </div>
80 );
81 }
82