Skip to content

Commit

Permalink
fix(tooltip): addind new pro to control max width inside componente
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasMurtaVI committed Jun 12, 2024
1 parent ceb3710 commit ddb6088
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,10 @@ export namespace Components {
* Method for change the visibility of tooltip.
*/
"invisible": () => Promise<void>;
/**
* Used to set tooltip max width
*/
"maxWidth": string;
/**
* Used to set tooltip position
*/
Expand Down Expand Up @@ -6053,6 +6057,10 @@ declare namespace LocalJSX {
* Used to disable tooltip when the button are avalible
*/
"disabled"?: boolean;
/**
* Used to set tooltip max width
*/
"maxWidth"?: string;
/**
* Used to set tooltip position
*/
Expand Down
1 change: 1 addition & 0 deletions src/components/tooltip/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| ------------- | -------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |
| `dataTest` | `data-test` | Data test is the prop to specifically test the component action object. | `string` | `null` |
| `disabled` | `disabled` | Used to disable tooltip when the button are avalible | `boolean` | `false` |
| `maxWidth` | `max-width` | Used to set tooltip max width | `string` | `'320px'` |
| `position` | `position` | Used to set tooltip position | `"bottom-center" \| "bottom-left" \| "bottom-right" \| "left-bottom" \| "left-center" \| "left-top" \| "right-bottom" \| "right-center" \| "right-top" \| "top-center" \| "top-left" \| "top-right"` | `'left-center'` |
| `tooltipText` | `tooltip-text` | Used to set tooltip text | `string` | `'Tooltip'` |

Expand Down
14 changes: 13 additions & 1 deletion src/components/tooltip/tooltip.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export default {
export const Properties = (args) => {
return (
<bds-grid margin="auto">
<bds-tooltip position={args.position} tooltip-text={args.tooltipText} disabled={args.disabled}>
<bds-tooltip
position={args.position}
tooltip-text={args.tooltipText}
disabled={args.disabled}
max-width={args.maxWidth}
>
<bds-button>Hover me</bds-button>
</bds-tooltip>
</bds-grid>
Expand All @@ -25,6 +30,7 @@ Properties.args = {
disabled: false,
position: 'right-center',
tooltipText: 'Tooltip',
maxWidth: '',
};

Properties.argTypes = {
Expand Down Expand Up @@ -60,6 +66,12 @@ Properties.argTypes = {
},
control: 'text',
},
maxWidth: {
table: {
defaultValue: { summary: 'vazio' },
},
control: 'text',
},
};

export const Methods = () => {
Expand Down
17 changes: 17 additions & 0 deletions src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class Tooltip {
*/
@State() isMouseOver = false;
@State() textVerify: string;
@State() maxWidtTooltip: string;

/**
* Used to set tooltip text
*/
Expand All @@ -40,6 +42,11 @@ export class Tooltip {
*/
@Prop() position: TooltipPostionType = 'left-center';

/**
* Used to set tooltip max width
*/
@Prop() maxWidth: string = '320px';

/**
* Data test is the prop to specifically test the component action object.
*/
Expand Down Expand Up @@ -71,14 +78,23 @@ export class Tooltip {

componentWillLoad() {
this.textVerify = this.tooltipText ? this.tooltipText.replace(/<br>/gi, '\r\n') : '';
this.maxWidtTooltip = this.maxWidth;
}

@Watch('tooltipText')
tooltipTextChanged(): void {
this.textVerify = this.tooltipText ? this.tooltipText.replace(/<br>/gi, '\r\n') : '';
}

@Watch('maxWidth')
maxWidthChanged(): void {
this.maxWidtTooltip = this.maxWidth;
}

render() {
const styleTooltip = {
maxWidth: this.maxWidtTooltip,
};
return (
<div class="tooltip__wrapper">
<div
Expand All @@ -94,6 +110,7 @@ export class Tooltip {
[`tooltip__tip--${this.position}`]: true,
'tooltip__tip--visible': this.isMouseOver,
}}
style={styleTooltip}
>
<div class={{ tooltip__tip__text: true }}>
<pre>
Expand Down

0 comments on commit ddb6088

Please sign in to comment.