Skip to content

New Feature: disableMaxHeight #2361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/ui/buttons/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export type ButtonStyle = {|
period?: number,
height?: number,
disableMaxWidth?: boolean,
disableMaxHeight?: boolean,
borderRadius?: number,
|};

Expand All @@ -332,6 +333,7 @@ export type ButtonStyleInputs = {|
period?: number | void,
height?: number | void,
disableMaxWidth?: boolean | void,
disableMaxHeight?: boolean | void,
borderRadius?: number | void,
|};

Expand Down Expand Up @@ -624,6 +626,7 @@ export function normalizeButtonStyle(
period,
menuPlacement = MENU_PLACEMENT.BELOW,
disableMaxWidth,
disableMaxHeight,
borderRadius,
} = style;

Expand Down Expand Up @@ -672,7 +675,13 @@ export function normalizeButtonStyle(
BUTTON_SIZE_STYLE[BUTTON_SIZE.HUGE].maxHeight,
];

if (height < minHeight || height > maxHeight) {
if (disableMaxHeight && height < minHeight) {
throw new Error(
`Expected style.height to be greater than ${minHeight}px - got ${height}px`
);
}

if (!disableMaxHeight && (height < minHeight || height > maxHeight)) {
throw new Error(
`Expected style.height to be between ${minHeight}px and ${maxHeight}px - got ${height}px`
);
Expand Down Expand Up @@ -711,6 +720,7 @@ export function normalizeButtonStyle(
period,
menuPlacement,
disableMaxWidth,
disableMaxHeight,
borderRadius,
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/ui/buttons/style.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ export function Style({
nonce,
fundingEligibility,
}: StyleProps): ElementNode {
const { height, disableMaxWidth, borderRadius } = style;
const { height, disableMaxWidth, disableMaxHeight, borderRadius } = style;
const css = componentStyle({
height,
fundingEligibility,
disableMaxWidth,
disableMaxHeight,
borderRadius,
});

Expand Down
3 changes: 3 additions & 0 deletions src/ui/buttons/styles/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export function componentStyle({
height,
fundingEligibility,
disableMaxWidth,
disableMaxHeight,
borderRadius,
}: {|
height?: ?number,
fundingEligibility: FundingEligibilityType,
disableMaxWidth?: ?boolean,
disableMaxHeight?: ?boolean,
borderRadius?: ?number,
|}): string {
return `
Expand All @@ -28,6 +30,7 @@ export function componentStyle({
height,
fundingEligibility,
disableMaxWidth,
disableMaxHeight,
borderRadius,
})}
`;
Expand Down
18 changes: 15 additions & 3 deletions src/ui/buttons/styles/responsive.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ export function buttonResponsiveStyle({
height,
fundingEligibility,
disableMaxWidth,
disableMaxHeight,
borderRadius,
}: {|
height?: ?number,
fundingEligibility: FundingEligibilityType,
disableMaxWidth?: ?boolean,
disableMaxHeight?: ?boolean,
borderRadius?: ?number,
|}): string {
return Object.keys(BUTTON_SIZE_STYLE)
.map((size) => {
const style = BUTTON_SIZE_STYLE[size];

const buttonHeight = height || style.defaultHeight;
const minDualWidth = Math.max(
Math.round(
Expand Down Expand Up @@ -67,6 +70,7 @@ export function buttonResponsiveStyle({
.${CLASS.CONTAINER} {
min-width: ${style.minWidth}px;
${disableMaxWidth ? "" : `max-width: ${style.maxWidth}px;`};
${disableMaxHeight ? "height: 100%;" : ""};
}

.${CLASS.CONTAINER} .${CLASS.BUTTON_ROW} .${CLASS.TEXT}, .${
Expand All @@ -82,10 +86,18 @@ export function buttonResponsiveStyle({
}

.${CLASS.BUTTON_ROW} {
height: ${buttonHeight}px;
height: ${disableMaxHeight ? "100%" : `${buttonHeight}px`};
vertical-align: top;
min-height: ${height || style.minHeight}px;
max-height: ${height || style.maxHeight}px;
${
disableMaxHeight
? ""
: ` min-height: ${height || style.minHeight}px;`
};
${
disableMaxHeight
? ""
: `max-height: ${height || style.maxHeight}px;`
}
}

.${CLASS.BUTTON_ROW}.${CLASS.LAYOUT}-${BUTTON_LAYOUT.VERTICAL} {
Expand Down
15 changes: 11 additions & 4 deletions src/zoid/buttons/container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ export function containerTemplate({

// $FlowFixMe
const { style, nonce } = props;
const { label, layout, height: buttonHeight, menuPlacement } = style;
const {
label,
layout,
height: buttonHeight,
menuPlacement,
disableMaxHeight,
} = style;

let minimumSize = MINIMUM_SIZE[layout];

if (buttonHeight) {
if (buttonHeight && !disableMaxHeight) {
const possibleSizes = values(BUTTON_SIZE).filter((possibleSize) => {
return (
BUTTON_SIZE_STYLE[possibleSize] &&
Expand Down Expand Up @@ -97,8 +103,9 @@ export function containerTemplate({
if (typeof newWidth === "number") {
el.style.width = toCSS(newWidth);
}

if (typeof newHeight === "number") {
if (disableMaxHeight) {
el.style.height = "100%";
} else if (typeof newHeight === "number") {
el.style.height = toCSS(newHeight);
}
});
Expand Down
16 changes: 13 additions & 3 deletions test/integration/tests/button/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,17 +852,27 @@ const buttonConfigs = [
height: 20,
valid: false,
},
{
disableMaxHeight: true,
height: 20,
valid: false,
},
{
disableMaxHeight: true,
height: 60,
valid: true,
},

// $FlowFixMe
].map(({ height, size, valid }) => ({
].map(({ height, valid, disableMaxHeight }) => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't seem like size was used at all in this sections so I removed it and used the sentence structure to indicate if the disbaleMaxHeight feature was enabled.

desc: `height ${height} with size ${
size !== undefined ? size : "default"
disableMaxHeight === true ? "disableMaxHeight" : "default"
}`,

valid,

conf: {
style: { height, size },
style: { height, disableMaxHeight },
createOrder: noop,
onApprove: noop,
},
Expand Down
Loading