Skip to content

Commit

Permalink
Fix #3193: Button/SplitButton visible property (#3194)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Aug 26, 2022
1 parent e35ef62 commit 635aeed
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 9 deletions.
12 changes: 12 additions & 0 deletions api-generator/components/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ const ButtonProps = [
default: 'null',
description: 'Configuration of the tooltip, refer to the tooltip documentation for more information.'
},
{
name: 'disabled',
type: 'boolean',
default: 'false',
description: 'When present, it specifies that the element should be disabled.'
},
{
name: 'visible',
type: 'boolean',
default: 'true',
description: 'When present, it specifies that the element should be visible.'
},
{
name: 'loading',
type: 'boolean',
Expand Down
6 changes: 6 additions & 0 deletions api-generator/components/splitbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const SplitButtonProps = [
default: 'false',
description: 'When present, it specifies that the component should be disabled.'
},
{
name: 'visible',
type: 'boolean',
default: 'true',
description: 'When present, it specifies that the element should be visible.'
},
{
name: 'style',
type: 'string',
Expand Down
18 changes: 15 additions & 3 deletions components/doc/button/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { memo } from 'react';
import Link from 'next/link';
import { TabView, TabPanel } from '../../lib/tabview/TabView';
import { useLiveEditorTabs } from '../common/liveeditor';
import React, { memo } from 'react';
import { TabPanel, TabView } from '../../lib/tabview/TabView';
import { CodeHighlight } from '../common/codehighlight';
import { DevelopmentSection } from '../common/developmentsection';
import { useLiveEditorTabs } from '../common/liveeditor';

const ButtonDoc = memo(() => {
const sources = {
Expand Down Expand Up @@ -1091,6 +1091,18 @@ import { Button } from 'primereact/button';
<td>null</td>
<td>Configuration of the tooltip, refer to the tooltip documentation for more information.</td>
</tr>
<tr>
<td>disabled</td>
<td>boolean</td>
<td>false</td>
<td>When present, it specifies that the element should be disabled.</td>
</tr>
<tr>
<td>visible</td>
<td>boolean</td>
<td>true</td>
<td>When present, it specifies that the element should be visible.</td>
</tr>
<tr>
<td>loading</td>
<td>boolean</td>
Expand Down
12 changes: 9 additions & 3 deletions components/doc/splitbutton/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { memo } from 'react';
import Link from 'next/link';
import { TabView, TabPanel } from '../../lib/tabview/TabView';
import { useLiveEditorTabs } from '../common/liveeditor';
import React, { memo } from 'react';
import { TabPanel, TabView } from '../../lib/tabview/TabView';
import { CodeHighlight } from '../common/codehighlight';
import { DevelopmentSection } from '../common/developmentsection';
import { useLiveEditorTabs } from '../common/liveeditor';

const SplitButtonDoc = memo(() => {
const sources = {
Expand Down Expand Up @@ -637,6 +637,12 @@ export const SplitButtonDemo = () => {
<td>false</td>
<td>When present, it specifies that the component should be disabled.</td>
</tr>
<tr>
<td>visible</td>
<td>boolean</td>
<td>true</td>
<td>When present, it specifies that the element should be visible.</td>
</tr>
<tr>
<td>style</td>
<td>string</td>
Expand Down
4 changes: 4 additions & 0 deletions components/lib/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export const Button = React.memo(
ObjectUtils.combinedRefs(elementRef, ref);
}, [elementRef, ref]);

if (props.visible === false) {
return null;
}

const createIcon = () => {
const icon = props.loading ? props.loadingIcon : props.icon;
const className = classNames('p-button-icon p-c', {
Expand Down
1 change: 1 addition & 0 deletions components/lib/button/button.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ButtonProps extends Omit<React.DetailedHTMLProps<React.ButtonHT
tooltip?: string;
tooltipOptions?: TooltipOptions;
disabled?: boolean;
visible?: boolean;
loading?: boolean;
loadingIcon?: IconType<ButtonProps>;
children?: React.ReactNode;
Expand Down
4 changes: 4 additions & 0 deletions components/lib/splitbutton/SplitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export const SplitButton = React.memo(
return null;
};

if (props.visible === false) {
return null;
}

const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip);
const otherProps = ObjectUtils.findDiffKeys(props, SplitButton.defaultProps);
const className = classNames('p-splitbutton p-component', props.className, { 'p-disabled': props.disabled });
Expand Down
3 changes: 2 additions & 1 deletion components/lib/splitbutton/splitbutton.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { CSSTransitionProps } from '../csstransition';
import { MenuItem } from '../menuitem';
import TooltipOptions from '../tooltip/tooltipoptions';
import { CSSTransitionProps } from '../csstransition';
import { IconType, TemplateType } from '../utils';

type SplitButtonAppendToType = 'self' | HTMLElement | undefined | null;
Expand All @@ -13,6 +13,7 @@ export interface SplitButtonProps extends Omit<React.DetailedHTMLProps<React.HTM
loadingIcon?: IconType<SplitButtonProps>;
model?: MenuItem[];
disabled?: boolean;
visible?: boolean;
buttonClassName?: string;
menuStyle?: object;
menuClassName?: string;
Expand Down
4 changes: 2 additions & 2 deletions pages/button/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Head from 'next/head';
import React, { useState } from 'react';
import { Button } from '../../components/lib/button/Button';
import ButtonDoc from '../../components/doc/button';
import { DocActions } from '../../components/doc/common/docactions';
import Head from 'next/head';
import { Button } from '../../components/lib/button/Button';

const ButtonDemo = () => {
const [loading1, setLoading1] = useState(false);
Expand Down

0 comments on commit 635aeed

Please sign in to comment.