Skip to content
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

feat: compressed theme layout #320

Merged
merged 14 commits into from
May 2, 2024
9 changes: 9 additions & 0 deletions src/BrutalTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ let brutalRules = (theme: CardThemeType.themeClass) =>
"color": theme.colorText,
"borderRadius": theme.borderRadius,
},
".Input-Compressed": {
"border": `0.1em solid #000000`,
"boxShadow": "0.12em 0.12em",
"color": theme.colorText,
},
".Input:-webkit-autofill": {
"transition": "background-color 5000s ease-in-out 0s",
"-webkitTextFillColor": `${theme.colorText} !important`,
Expand All @@ -98,6 +103,10 @@ let brutalRules = (theme: CardThemeType.themeClass) =>
"transform": "translate(0.05em, 0.05em)",
"boxShadow": "0.02em 0.02em",
},
".Input-Compressed:focus": {
"transform": "translate(0.02em, 0.02em)",
"boxShadow": "0.01em 0.01em",
},
".Input--invalid": {
"border": `0.1em solid ${theme.colorDangerText}`,
"color": theme.colorDanger,
Expand Down
19 changes: 18 additions & 1 deletion src/CardTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ let getTheme = (val, logger) => {
}
}
}

let getInnerLayout = str => {
switch str {
| "compressed" => Compressed
| "spaced"
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
| _ =>
Spaced
}
}

let getShowLoader = (str, logger) => {
switch str {
| "auto" => Auto
Expand All @@ -38,6 +48,7 @@ let defaultAppearance = {
componentType: "payment",
labels: Above,
rules: Dict.make()->JSON.Encode.object,
innerLayout: Spaced,
}
let defaultFonts = {
cssSrc: "",
Expand Down Expand Up @@ -305,7 +316,12 @@ let getAppearance = (
->Dict.get(str)
->Option.flatMap(JSON.Decode.object)
->Option.map(json => {
unknownKeysWarning(["theme", "variables", "rules", "labels"], json, "appearance", ~logger)
unknownKeysWarning(
["theme", "variables", "rules", "labels", "innerLayout"],
json,
"appearance",
~logger,
)

let rulesJson = defaultRules(getVariables("variables", json, default, logger))

Expand All @@ -314,6 +330,7 @@ let getAppearance = (
componentType: getWarningString(json, "componentType", "", ~logger),
variables: getVariables("variables", json, default, logger),
rules: mergeJsons(rulesJson, getJsonObjectFromDict(json, "rules")),
innerLayout: getWarningString(json, "innerLayout", "spaced", ~logger)->getInnerLayout,
labels: switch getWarningString(json, "labels", "above", ~logger) {
| "above" => Above
| "floating" => Floating
Expand Down
11 changes: 11 additions & 0 deletions src/CharcoalTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ let charcoalRules = theme =>
"color": theme.colorText,
"borderRadius": theme.borderRadius,
},
".Input-Compressed": {
"border": `1px solid ${theme.colorBackground}`,
"fontWeight": theme.fontWeightLight,
"color": theme.colorText,
},
".Input:-webkit-autofill": {
"transition": "background-color 5000s ease-in-out 0s",
"-webkitTextFillColor": `${theme.colorText} !important`,
Expand All @@ -97,6 +102,12 @@ let charcoalRules = theme =>
"border": `1px solid ${theme.colorPrimary}`,
"boxShadow": `${theme.colorPrimary}4c 0px 0px 0px 3px`,
},
".Input-Compressed:focus": {
"border": `2px solid ${theme.colorPrimary}`,
"boxShadow": `${theme.colorPrimary}4c 0px 0px 0px 2px`,
"position": "relative",
"zIndex": "2",
},
".Input--invalid": {
"color": theme.colorDanger,
"border": `2px solid ${theme.colorDanger}`,
Expand Down
3 changes: 2 additions & 1 deletion src/Components/BillingNamePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open Utils

@react.component
let make = (~paymentType, ~customFieldName=None, ~requiredFields as optionalRequiredFields=?) => {
let {localeString} = Recoil.useRecoilValueFromAtom(configAtom)
let {config, localeString} = Recoil.useRecoilValueFromAtom(configAtom)
let {fields} = Recoil.useRecoilValueFromAtom(optionAtom)
let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom)

Expand Down Expand Up @@ -74,6 +74,7 @@ let make = (~paymentType, ~customFieldName=None, ~requiredFields as optionalRequ
name="name"
inputRef=nameRef
placeholder
className={config.appearance.innerLayout === Spaced ? "" : "!border-b-0"}
/>
</RenderIf>
}
10 changes: 8 additions & 2 deletions src/Components/DropdownField.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let make = (
let dropdownRef = React.useRef(Nullable.null)
let (inputFocused, setInputFocused) = React.useState(_ => false)
let {parentURL} = Recoil.useRecoilValueFromAtom(keys)
let isSpacedInnerLayout = config.appearance.innerLayout === Spaced

let handleFocus = _ => {
setInputFocused(_ => true)
Expand Down Expand Up @@ -46,7 +47,10 @@ let make = (
let cursorClass = !disabled ? "cursor-pointer" : "cursor-not-allowed"
<RenderIf condition={options->Array.length > 0}>
<div className="flex flex-col w-full">
<RenderIf condition={fieldName->String.length > 0 && appearance.labels == Above}>
<RenderIf
condition={fieldName->String.length > 0 &&
appearance.labels == Above &&
isSpacedInnerLayout}>
<div
className={`Label `}
style={ReactDOMStyle.make(
Expand Down Expand Up @@ -74,7 +78,9 @@ let make = (
disabled={readOnly || disabled}
onChange=handleChange
onFocus=handleFocus
className={`Input ${className} w-full appearance-none outline-none ${cursorClass}`}>
className={`${isSpacedInnerLayout
? "Input"
: "Input-Compressed"} ${className} w-full appearance-none outline-none ${cursorClass}`}>
{options
->Array.mapWithIndex((item: string, i) => {
<option key={Int.toString(i)} value=item> {React.string(item)} </option>
Expand Down
53 changes: 40 additions & 13 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ let make = (
}, (requiredFields, isAllStoredCardsHaveName, isSavedCardFlow))

let {config, themeObj, localeString} = Recoil.useRecoilValueFromAtom(configAtom)
let isSpacedInnerLayout = config.appearance.innerLayout === Spaced

let logger = Recoil.useRecoilValueFromAtom(loggerAtom)

Expand Down Expand Up @@ -435,11 +436,22 @@ let make = (
options=currencyArr
/>
| FullName =>
<FullNamePaymentInput
paymentType
customFieldName={item->getCustomFieldName}
optionalRequiredFields={Some(requiredFields)}
/>
<>
<div
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
style={ReactDOMStyle.make(
~marginBottom="5px",
~fontSize=themeObj.fontSizeLg,
~opacity="0.6",
(),
)}>
{item->getCustomFieldName->Option.getOr("")->React.string}
</div>
<FullNamePaymentInput
paymentType
customFieldName={item->getCustomFieldName}
optionalRequiredFields={Some(requiredFields)}
/>
</>
| Email
| InfoElement
| Country
Expand All @@ -463,15 +475,26 @@ let make = (
->React.array}
<RenderIf condition={isRenderDynamicFieldsInsideBilling}>
<div
className="p-2 w-full text-left"
className={`${isSpacedInnerLayout ? "p-2" : "my-2"} w-full text-left`}
style={ReactDOMStyle.make(
~border=`1px solid ${themeObj.borderColor}`,
~borderRadius=themeObj.borderRadius,
~margin=`10px 0`,
~border={isSpacedInnerLayout ? `1px solid ${themeObj.borderColor}` : ""},
~borderRadius={isSpacedInnerLayout ? themeObj.borderRadius : ""},
~margin={isSpacedInnerLayout ? `10px 0` : ""},
(),
)}>
{React.string(localeString.billingDetailsText)}
<div className="p-2 flex flex-col gap-2">
<div
style={ReactDOMStyle.make(
~marginBottom="5px",
~fontSize=themeObj.fontSizeLg,
~opacity="0.6",
(),
)}>
{React.string(localeString.billingDetailsText)}
</div>
<div
className={`${isSpacedInnerLayout ? "p-2" : ""} flex flex-col ${isSpacedInnerLayout
? "gap-2"
: ""}`}>
{dynamicFieldsToRenderInsideBilling
->Array.mapWithIndex((item, index) => {
<div
Expand All @@ -482,7 +505,7 @@ let make = (
| Email => <EmailPaymentInput paymentType />
| PhoneNumber => <PhoneNumberPaymentInput />
| StateAndCity =>
<div className="flex gap-1">
<div className={`flex ${isSpacedInnerLayout ? "gap-1" : ""}`}>
<PaymentField
fieldName=localeString.cityLabel
setValue={setCity}
Expand All @@ -507,6 +530,7 @@ let make = (
name="city"
inputRef=cityRef
placeholder=localeString.cityLabel
className={isSpacedInnerLayout ? "" : "!border-r-0"}
/>
{switch stateJson {
| Some(options) =>
Expand All @@ -524,14 +548,15 @@ let make = (
}}
</div>
| CountryAndPincode(countryArr) =>
<div className="flex gap-1">
<div className={`flex ${isSpacedInnerLayout ? "gap-1" : ""}`}>
<DropdownField
appearance=config.appearance
fieldName=localeString.countryLabel
value=country
setValue={setCountry}
disabled=false
options=countryArr
className={isSpacedInnerLayout ? "" : "!border-t-0 !border-r-0"}
/>
<PaymentField
fieldName=localeString.postalCodeLabel
Expand All @@ -549,6 +574,7 @@ let make = (
name="postal"
inputRef=postalRef
placeholder=localeString.postalCodeLabel
className={isSpacedInnerLayout ? "" : "!border-t-0"}
/>
</div>
| AddressLine1 =>
Expand Down Expand Up @@ -576,6 +602,7 @@ let make = (
name="line1"
inputRef=line1Ref
placeholder=localeString.line1Placeholder
className={isSpacedInnerLayout ? "" : "!border-b-0"}
/>
| AddressLine2 =>
<PaymentField
Expand Down
6 changes: 5 additions & 1 deletion src/Components/FullNamePaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ open PaymentType
open Utils

@react.component
let make = (~paymentType, ~customFieldName=None, ~optionalRequiredFields=None) => {
let make = (
~paymentType: CardThemeType.mode,
~customFieldName=None,
~optionalRequiredFields=None,
) => {
let {localeString} = Recoil.useRecoilValueFromAtom(configAtom)
let {fields} = Recoil.useRecoilValueFromAtom(optionAtom)
let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom)
Expand Down
10 changes: 8 additions & 2 deletions src/Components/PaymentDropDownField.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let make = (
let dropdownRef = React.useRef(Nullable.null)
let (inputFocused, setInputFocused) = React.useState(_ => false)
let {parentURL} = Recoil.useRecoilValueFromAtom(keys)
let isSpacedInnerLayout = config.appearance.innerLayout === Spaced

let getClassName = initialLabel => {
if value.value->String.length == 0 {
Expand Down Expand Up @@ -74,7 +75,10 @@ let make = (
let cursorClass = !disabled ? "cursor-pointer" : "cursor-not-allowed"
<RenderIf condition={options->Array.length > 0}>
<div className="flex flex-col w-full" style={ReactDOMStyle.make(~color=themeObj.colorText, ())}>
<RenderIf condition={fieldName->String.length > 0 && config.appearance.labels == Above}>
<RenderIf
condition={fieldName->String.length > 0 &&
config.appearance.labels == Above &&
isSpacedInnerLayout}>
<div
className={`Label ${labelClass} `}
style={ReactDOMStyle.make(
Expand Down Expand Up @@ -102,7 +106,9 @@ let make = (
disabled={readOnly || disabled}
onFocus={handleFocus}
onChange=handleChange
className={`Input ${inputClass} ${className} w-full appearance-none outline-none ${cursorClass}`}>
className={`${isSpacedInnerLayout
? "Input"
: "Input-Compressed"} ${inputClass} ${className} w-full appearance-none outline-none ${cursorClass}`}>
{options
->Array.mapWithIndex((item: string, i) => {
<option key={Int.toString(i)} value=item> {React.string(item)} </option>
Expand Down
10 changes: 8 additions & 2 deletions src/Components/PaymentField.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let make = (
let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom)
let {readOnly} = Recoil.useRecoilValueFromAtom(optionAtom)
let {parentURL} = Recoil.useRecoilValueFromAtom(keys)
let isSpacedInnerLayout = config.appearance.innerLayout === Spaced

let (inputFocused, setInputFocused) = React.useState(_ => false)

Expand Down Expand Up @@ -77,7 +78,10 @@ let make = (
let inputClass = getClassName("Input")

<div className="flex flex-col w-full" style={ReactDOMStyle.make(~color=themeObj.colorText, ())}>
<RenderIf condition={fieldName->String.length > 0 && config.appearance.labels == Above}>
<RenderIf
condition={fieldName->String.length > 0 &&
config.appearance.labels == Above &&
isSpacedInnerLayout}>
<div
className={`Label ${labelClass}`}
style={ReactDOMStyle.make(
Expand Down Expand Up @@ -105,7 +109,9 @@ let make = (
name
?maxLength
?pattern
className={`Input ${inputClass} ${className} focus:outline-none transition-shadow ease-out duration-200`}
className={`${isSpacedInnerLayout
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
? "Input"
: "Input-Compressed"} ${inputClass} ${className} focus:outline-none transition-shadow ease-out duration-200`}
placeholder={config.appearance.labels == Above || config.appearance.labels == Never
? placeholder
: ""}
Expand Down
Loading
Loading