Skip to content

Commit

Permalink
Merge branch 'staging' of https://github.com/brainstormforce/force-ui
Browse files Browse the repository at this point in the history
…into SUR-289
  • Loading branch information
vrundakansara committed Sep 25, 2024
2 parents d53b2e7 + 2786bab commit 173acbd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/force-ui.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom'), 'version' => '2313942efbf357138322');
<?php return array('dependencies' => array('react', 'react-dom'), 'version' => 'bf6216ffd684ee62b8cd');
2 changes: 1 addition & 1 deletion dist/force-ui.js

Large diffs are not rendered by default.

33 changes: 16 additions & 17 deletions src/components/switch/switch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import { nanoid } from 'nanoid';
import { cn } from '@/utilities/functions';

const SwitchLabel = ( { label, switchId, disabled = false, children } ) => {
const isEmptyLabel = ! label?.heading || ! label?.description;

const isLabelAComponent = isValidElement( label );

const renderLabel = useCallback( () => {
if ( isLabelAComponent ) {
return label;
}

const { heading = '', description = '' } = label;
if ( isLabelAComponent ) {
return (
<div className={ cn( 'inline-flex items-center gap-3', 'items-start' ) }>
{ children }
{ label }
</div>
);
}
const renderLabel = () => {
const { heading = '', description = '' } = label || {};
return (
<div className="space-y-1.5">
{ heading && (
Expand All @@ -33,23 +34,21 @@ const SwitchLabel = ( { label, switchId, disabled = false, children } ) => {
) }
</div>
);
}, [ label ] );
};

const isEmptyLabel = ! label?.heading && ! label?.description;
const alignmentClass = ! label?.heading || ! label?.description ? 'items-center' : 'items-start';

if ( isEmptyLabel ) {
return children;
}

return (
<div
className={ cn(
'inline-flex items-center',
! isEmptyLabel && 'items-start'
) }
>
<div className={ cn( 'inline-flex', alignmentClass, 'gap-3' ) }>
{ children }
<label
htmlFor={ switchId }
className={ cn( 'ml-3', ! disabled && 'cursor-pointer' ) }
className={ cn( ! disabled && 'cursor-pointer' ) }
>
{ renderLabel() }
</label>
Expand Down

0 comments on commit 173acbd

Please sign in to comment.