Skip to content

Commit

Permalink
feat(SpacingUtils): deprecate createStyleObject (#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
langz authored and tujoworker committed May 31, 2023
1 parent 82d158c commit 421a0a8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 43 deletions.
31 changes: 0 additions & 31 deletions packages/dnb-eufemia/src/components/space/SpacingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,37 +275,6 @@ export const removeSpaceProps = (props: StyleObjectProps) => {
return p
}

// deprecated and can be removed in v10 (remove tests as well)
export const createStyleObject = (props: StyleObjectProps) => {
const p = Object.isFrozen(props) ? { ...props } : props

if (p.top && !(parseFloat(String(p.top)) > 0)) {
p.top = sumTypes(p.top)
}
if (p.bottom && !(parseFloat(String(p.bottom)) > 0)) {
p.bottom = sumTypes(p.bottom)
}
if (p.left && !(parseFloat(String(p.left)) > 0)) {
p.left = sumTypes(p.left)
}
if (p.right && !(parseFloat(String(p.right)) > 0)) {
p.right = sumTypes(p.right)
}
return Object.entries({
marginTop: p.top && `${p.top}rem`,
marginBottom: p.bottom && `${p.bottom}rem`,
maxWidth: p.maxWidth && `${p.maxWidth}rem`,
maxHeight: p.maxHeight && `${p.maxHeight}rem`,
width: p.width && `${p.width}rem`,
height: p.height && `${p.height}rem`,
}).reduce((acc, [key, val]) => {
if (typeof val !== 'undefined') {
acc[key] = val
}
return acc
}, {})
}

export const isInline = (elementName: string) => {
switch (elementName) {
case 'h1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
findType,
findNearestTypes,
isValidSpaceProp,
createStyleObject,
createSpacingClasses,
} from '../SpacingUtils'
import { spacingPropTypes } from '../SpacingHelper'
Expand Down Expand Up @@ -241,17 +240,6 @@ describe('createSpacingClasses', () => {
})
})

describe('createStyleObject', () => {
it('should create a valid style object', () => {
expect(createStyleObject({ top: 'medium large' })).toEqual({
marginTop: '3.5rem',
})
expect(createStyleObject({ top: '3.5' })).toEqual({
marginTop: '3.5rem',
})
})
})

describe('SpacingHelper', () => {
it('should have valid spacingPropTypes', () => {
expect(typeof spacingPropTypes.space).toBe('function')
Expand Down

0 comments on commit 421a0a8

Please sign in to comment.