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: support padding for mobile replay styling #21020

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
149 changes: 146 additions & 3 deletions ee/frontend/mobile-replay/__snapshots__/transform.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ exports[`replay/transform transform incremental mutations de-duplicate the tree
"node": {
"attributes": {
"data-rrweb-id": 99571736,
"style": "color: #000000;width: 150px;height: 19px;position: fixed;left: 10px;top: 584px;align-items: flex-start;justify-content: flex-start;display: flex;font-size: 14px;font-family: sans-serif;overflow:hidden;white-space:normal;",
"style": "color: #000000;width: 150px;height: 19px;position: fixed;left: 10px;top: 584px;align-items: flex-start;justify-content: flex-start;display: flex;padding-left: 0px;padding-right: 0px;padding-top: 0px;padding-bottom: 0px;font-size: 14px;font-family: sans-serif;overflow:hidden;white-space:normal;",
},
"childNodes": [],
"id": 99571736,
Expand All @@ -1404,7 +1404,7 @@ exports[`replay/transform transform incremental mutations de-duplicate the tree
"node": {
"attributes": {
"data-rrweb-id": 240124529,
"style": "color: #000000;width: 48px;height: 32px;position: fixed;left: 10px;top: 548px;align-items: center;justify-content: center;display: flex;font-size: 14px;font-family: sans-serif;overflow:hidden;white-space:normal;",
"style": "color: #000000;width: 48px;height: 32px;position: fixed;left: 10px;top: 548px;align-items: center;justify-content: center;display: flex;padding-left: 32px;padding-right: 0px;padding-top: 6px;padding-bottom: 6px;font-size: 14px;font-family: sans-serif;overflow:hidden;white-space:normal;",
},
"childNodes": [],
"id": 240124529,
Expand All @@ -1427,7 +1427,7 @@ exports[`replay/transform transform incremental mutations de-duplicate the tree
"node": {
"attributes": {
"data-rrweb-id": 52129787,
"style": "color: #000000;width: 368px;height: 19px;position: fixed;left: 66px;top: 556px;align-items: flex-start;justify-content: flex-start;display: flex;font-size: 14px;font-family: sans-serif;overflow:hidden;white-space:normal;",
"style": "color: #000000;width: 368px;height: 19px;position: fixed;left: 66px;top: 556px;align-items: flex-start;justify-content: flex-start;display: flex;padding-left: 0px;padding-right: 0px;padding-top: 0px;padding-bottom: 0px;font-size: 14px;font-family: sans-serif;overflow:hidden;white-space:normal;",
},
"childNodes": [],
"id": 52129787,
Expand Down Expand Up @@ -5421,6 +5421,149 @@ exports[`replay/transform transform inputs input - url - https://example.io 1`]
}
`;

exports[`replay/transform transform inputs input gets 0 padding by default but can be overridden 1`] = `
{
"data": {
"initialOffset": {
"left": 0,
"top": 0,
},
"node": {
"childNodes": [
{
"id": 2,
"name": "html",
"publicId": "",
"systemId": "",
"type": 1,
},
{
"attributes": {
"data-rrweb-id": 3,
"style": "height: 100vh; width: 100vw;",
},
"childNodes": [
{
"attributes": {
"data-rrweb-id": 4,
},
"childNodes": [
{
"attributes": {
"type": "text/css",
},
"childNodes": [
{
"id": 101,
"textContent": "
body {
margin: unset;
}
input, button, select, textarea {
font: inherit;
margin: 0;
padding: 0;
border: 0;
outline: 0;
background: transparent;
}
.input:focus {
outline: none;
}
img {
border-style: none;
}
",
"type": 3,
},
],
"id": 100,
"tagName": "style",
"type": 2,
},
],
"id": 4,
"tagName": "head",
"type": 2,
},
{
"attributes": {
"data-rrweb-id": 5,
"style": "height: 100vh; width: 100vw;",
},
"childNodes": [
{
"attributes": {
"data-rrweb-id": 12359,
"style": "width: 100px;height: 30px;position: fixed;left: 0px;top: 0px;",
"type": "text",
"value": "",
},
"childNodes": [],
"id": 12359,
"tagName": "input",
"type": 2,
},
{
"attributes": {
"data-rrweb-id": 12361,
"style": "width: 100px;height: 30px;position: fixed;left: 0px;top: 0px;padding-left: 16px;padding-right: 16px;",
"type": "text",
"value": "",
},
"childNodes": [],
"id": 12361,
"tagName": "input",
"type": 2,
},
{
"attributes": {
"data-render-reason": "a fixed placeholder to contain the keyboard in the correct stacking position",
"data-rrweb-id": 9,
},
"childNodes": [],
"id": 9,
"tagName": "div",
"type": 2,
},
{
"attributes": {
"data-rrweb-id": 7,
},
"childNodes": [],
"id": 7,
"tagName": "div",
"type": 2,
},
{
"attributes": {
"data-rrweb-id": 11,
},
"childNodes": [],
"id": 11,
"tagName": "div",
"type": 2,
},
],
"id": 5,
"tagName": "body",
"type": 2,
},
],
"id": 3,
"tagName": "html",
"type": 2,
},
],
"id": 1,
"type": 0,
},
},
"timestamp": 1,
"type": 2,
}
`;

exports[`replay/transform transform inputs isolated add mutation 1`] = `
{
"data": {
Expand Down
16 changes: 16 additions & 0 deletions ee/frontend/mobile-replay/mobile.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ export type MobileStyles = {
* @description maps to CSS font-family. Accepts any valid CSS font-family value.
*/
fontFamily?: string
/**
* @description maps to CSS padding-left. Expects a number (treated as pixels) or a string that is a number followed by px e.g. 16px
*/
paddingLeft?: string | number
/**
* @description maps to CSS padding-right. Expects a number (treated as pixels) or a string that is a number followed by px e.g. 16px
*/
paddingRight?: string | number
/**
* @description maps to CSS padding-top. Expects a number (treated as pixels) or a string that is a number followed by px e.g. 16px
*/
paddingTop?: string | number
/**
* @description maps to CSS padding-bottom. Expects a number (treated as pixels) or a string that is a number followed by px e.g. 16px
*/
paddingBottom?: string | number
}

type wireframeBase = {
Expand Down
16 changes: 16 additions & 0 deletions ee/frontend/mobile-replay/schema/mobile/rr-mobile-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@
"enum": ["left", "right", "center"],
"type": "string"
},
"paddingBottom": {
"description": "maps to CSS padding-bottom. Expects a number (treated as pixels) or a string that is a number followed by px e.g. 16px",
"type": ["string", "number"]
},
"paddingLeft": {
"description": "maps to CSS padding-left. Expects a number (treated as pixels) or a string that is a number followed by px e.g. 16px",
"type": ["string", "number"]
},
"paddingRight": {
"description": "maps to CSS padding-right. Expects a number (treated as pixels) or a string that is a number followed by px e.g. 16px",
"type": ["string", "number"]
},
"paddingTop": {
"description": "maps to CSS padding-top. Expects a number (treated as pixels) or a string that is a number followed by px e.g. 16px",
"type": ["string", "number"]
},
"verticalAlign": {
"description": "vertical alignment with respect to its parent",
"enum": ["top", "bottom", "center"],
Expand Down
32 changes: 32 additions & 0 deletions ee/frontend/mobile-replay/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('replay/transform', () => {
beforeEach(async () => {
posthogEEModule = await posthogEE()
})

test('can process unknown types without error', () => {
expect(
posthogEEModule.mobileReplay?.transformToWeb([
Expand Down Expand Up @@ -535,6 +536,37 @@ describe('replay/transform', () => {
})

describe('inputs', () => {
test('input gets 0 padding by default but can be overridden', () => {
expect(
posthogEEModule.mobileReplay?.transformEventToWeb({
type: 2,
data: {
wireframes: [
{
id: 12359,
width: 100,
height: 30,
type: 'input',
inputType: 'text',
},
{
id: 12361,
width: 100,
height: 30,
type: 'input',
inputType: 'text',
style: {
paddingLeft: '16px',
paddingRight: 16,
},
},
],
},
timestamp: 1,
})
).toMatchSnapshot()
})

test('buttons with nested elements', () => {
expect(
posthogEEModule.mobileReplay?.transformEventToWeb({
Expand Down
15 changes: 15 additions & 0 deletions ee/frontend/mobile-replay/transformer/wireframeStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,24 @@ function makeLayoutStyles(wireframe: wireframe, styleOverride?: StyleOverride):
}`
)
}

if (styleParts.length) {
styleParts.push(`display: flex`)
}

if (isUnitLike(combinedStyles.paddingLeft)) {
styleParts.push(`padding-left: ${ensureUnit(combinedStyles.paddingLeft)}`)
}
if (isUnitLike(combinedStyles.paddingRight)) {
styleParts.push(`padding-right: ${ensureUnit(combinedStyles.paddingRight)}`)
}
if (isUnitLike(combinedStyles.paddingTop)) {
styleParts.push(`padding-top: ${ensureUnit(combinedStyles.paddingTop)}`)
}
if (isUnitLike(combinedStyles.paddingBottom)) {
styleParts.push(`padding-bottom: ${ensureUnit(combinedStyles.paddingBottom)}`)
}

return asStyleString(styleParts)
}

Expand Down
Loading