Skip to content

Commit

Permalink
Create a property to let the user select the ActiveTab
Browse files Browse the repository at this point in the history
  • Loading branch information
Franlop7 committed Sep 3, 2024
1 parent fad4615 commit d047eaa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export const TabsBarShape = forwardRef<any, ShapeProps>((props, ref) => {

const { handleSelection } = useShapeComponentSelection(props, shapeType);

const activeTab = otherProps?.activeTab ?? 0;

return (
<Group
x={x}
Expand All @@ -74,7 +76,7 @@ export const TabsBarShape = forwardRef<any, ShapeProps>((props, ref) => {
<Rect
width={tabWidth}
height={tabHeight}
fill={index === 0 ? 'white' : '#E0E0E0'} // First tab is selected
fill={index === activeTab ? 'white' : '#E0E0E0'} // First tab is selected
stroke="black"
strokeWidth={1}
/>
Expand Down
1 change: 1 addition & 0 deletions src/core/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export interface OtherProps {
imageBlackAndWhite?: boolean;
progress?: string;
borderRadius?: string;
activeTab?: number;
}

export const BASE_ICONS_URL = '/icons/';
Expand Down
4 changes: 4 additions & 0 deletions src/pods/canvas/canvas.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ export const generateDefaultOtherProps = (
progress: '50',
backgroundColor: '#A9A9A9',
};
case 'tabsbar':
return {
activeTab: 0,
};
default:
return undefined;
}
Expand Down
32 changes: 32 additions & 0 deletions src/pods/properties/properties.pod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ export const PropertiesPod = () => {

const selectedShapeData = getSelectedShapeData();

// Function to parse the tabsbar text and get the names of the tabs
const parseTabsBarText = (text: string): string[] => {
return text
.trim()
.split(',')
.map(row => row.trim());
};

// Checking whether the type is tabsbar and parsing the text
const isTabsBar = selectedShapeData?.type === 'tabsbar';
const tabs =
isTabsBar && selectedShapeData?.text
? parseTabsBarText(selectedShapeData.text)
: [];

return (
<div>
<div className={classes.title}>
Expand Down Expand Up @@ -126,6 +141,23 @@ export const PropertiesPod = () => {
}
/>
)}
{isTabsBar && (
<div>
<label>Active Tab</label>
<select
value={selectedShapeData?.otherProps?.activeTab}
onChange={e =>
updateOtherPropsOnSelected('activeTab', Number(e.target.value))
}
>
{tabs.map((tab, index) => (
<option key={index} value={index}>
{tab}
</option>
))}
</select>
</div>
)}
</div>
);
};

0 comments on commit d047eaa

Please sign in to comment.