PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.0
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.0
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.7.0, at gutenberg/components/responsive-tab-panel/index.js

82 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Button, Tooltip } from '@wordpress/components';
2 import { __, sprintf } from '@wordpress/i18n';
3 import classnames from 'classnames/dedupe';
4
5 import useResponsive from '../../hooks/use-responsive';
6 import getIcon from '../../utils/get-icon';
7 import ActiveIndicator from '../active-indicator';
8
9 /**
10 * Component Class
11 *
12 * @param props
13 */
14 export default function ResponsiveTabPanel(props) {
15 const { children } = props;
16
17 // Fallback for deprecated filledTabs prop.
18 const active = props?.active || props?.filledTabs || {};
19
20 const { allDevices, device, setDevice } = useResponsive();
21
22 const tabs = [];
23 const icons = [
24 getIcon('tabs-mobile'),
25 getIcon('tabs-tablet'),
26 getIcon('tabs-laptop'),
27 getIcon('tabs-desktop'),
28 getIcon('tabs-tv'),
29 ];
30
31 [...Object.keys(allDevices), ''].forEach((name, i) => {
32 tabs.unshift({
33 name,
34 title: (
35 <Tooltip
36 text={
37 !name
38 ? __('All devices', 'ghostkit')
39 : sprintf(
40 // translators: %s: breakpoint width in pixels, for example "768px".
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