@telus-uds/components-web 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,61 @@
1
+ import React, { forwardRef } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import styled from 'styled-components'
4
+ import { selectSystemProps } from '@telus-uds/components-base'
5
+ import { htmlAttrs } from '../utils'
6
+ import OrderedListBase from './OrderedListBase'
7
+ import Item from './Item'
8
+ import { OL_COUNTER_NAME } from './constants'
9
+
10
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs])
11
+
12
+ const StyledOrderedListBase = styled(OrderedListBase)(({ start }) => ({
13
+ // Using CSS counters here to have better control over the number styling
14
+ listStyle: 'none',
15
+ counterReset: `${OL_COUNTER_NAME} ${start - 1}`
16
+ }))
17
+
18
+ /**
19
+ * Themed semantic ordered list.
20
+ */
21
+ const OrderedList = forwardRef(({ children, start, variant, ...rest }, ref) => {
22
+ // Pass any variants "OrderedList" receives down to the individual list items.
23
+ const childrenWithParentVariants = variant
24
+ ? children.map((child) => {
25
+ const existingChildVariants = child.props?.variant ?? {}
26
+ return {
27
+ ...child,
28
+ props: {
29
+ ...child.props,
30
+ variant: {
31
+ ...existingChildVariants,
32
+ ...variant
33
+ }
34
+ }
35
+ }
36
+ })
37
+ : children
38
+ return (
39
+ <StyledOrderedListBase {...selectProps(rest)} ref={ref} start={start}>
40
+ {childrenWithParentVariants}
41
+ </StyledOrderedListBase>
42
+ )
43
+ })
44
+ OrderedList.displayName = 'OrderedList'
45
+
46
+ OrderedList.propTypes = {
47
+ ...selectedSystemPropTypes,
48
+ /**
49
+ * A list of ordered items wrapped in `OrderedList.Item`.
50
+ */
51
+ children: PropTypes.node.isRequired,
52
+ /**
53
+ * The position to start the list with.
54
+ */
55
+ start: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
56
+ }
57
+ OrderedList.defaultProps = { start: 1 }
58
+
59
+ OrderedList.Item = Item
60
+
61
+ export default OrderedList
@@ -0,0 +1,38 @@
1
+ import React, { forwardRef } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import styled from 'styled-components'
4
+ import ItemBase from './ItemBase'
5
+
6
+ const StyledList = styled.ol({
7
+ display: 'flex',
8
+ flexDirection: 'column',
9
+ listStylePosition: 'inside',
10
+ margin: 0,
11
+ padding: 0
12
+ })
13
+
14
+ /**
15
+ * Semantic ordered list.
16
+ */
17
+ const OrderedListBase = forwardRef(({ children, start, ...rest }, ref) => (
18
+ <StyledList {...rest} ref={ref} start={start}>
19
+ {children}
20
+ </StyledList>
21
+ ))
22
+ OrderedListBase.displayName = 'OrderedList'
23
+
24
+ OrderedListBase.propTypes = {
25
+ /**
26
+ * A list of ordered items wrapped in `OrderedListBase.Item`.
27
+ */
28
+ children: PropTypes.node.isRequired,
29
+ /**
30
+ * The position to start the list with.
31
+ */
32
+ start: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
33
+ }
34
+ OrderedListBase.defaultProps = { start: 1 }
35
+
36
+ OrderedListBase.Item = ItemBase
37
+
38
+ export default OrderedListBase
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export const OL_COUNTER_NAME = 'allium-ordered-list-counter'
@@ -0,0 +1,6 @@
1
+ import OrderedList from './OrderedList'
2
+ import Item from './Item'
3
+
4
+ OrderedList.Item = Item
5
+
6
+ export default OrderedList
@@ -0,0 +1,126 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import { selectSystemProps, Typography, useThemeTokens } from '@telus-uds/components-base'
4
+ // import palette from '@telus-uds/palette-allium/build/web/palette'
5
+ import styled from 'styled-components'
6
+ import { htmlAttrs } from '../utils'
7
+
8
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs])
9
+
10
+ const RibbonWrapper = styled.div`
11
+ width: fit-content;
12
+ position: ${({ left, top }) => (left ?? top ? 'absolute' : 'relative')};
13
+ z-index: 1;
14
+ left: ${({ left }) => left && `${left}px`};
15
+ top: ${({ top }) => top && `${top}px`};
16
+ `
17
+
18
+ const RibbonContainer = styled.div`
19
+ display: flex;
20
+ justify-content: center;
21
+ background: ${({ backgroundColor }) => backgroundColor};
22
+ padding: ${({ padding }) => `${padding}`};
23
+ border-radius: ${({ borderRadius }) => borderRadius};
24
+ width: fit-content;
25
+ box-shadow: ${({ boxShadow, shouldWrap }) => shouldWrap && boxShadow};
26
+ `
27
+
28
+ const RibbonCurve = styled.div`
29
+ background: ${({ curveBackgroundColor }) => curveBackgroundColor};
30
+ width: ${({ curveWidth }) => curveWidth};
31
+ height: ${({ curveHeight }) => curveHeight};
32
+ margin-top: -${({ curveMarginTop }) => curveMarginTop};
33
+ border-radius: 0 0 0 100%;
34
+ position: relative;
35
+ z-index: -1;
36
+ &::after {
37
+ content: '';
38
+ border-bottom-left-radius: ${({ curveAfterRadius }) => curveAfterRadius};
39
+ position: absolute;
40
+ height: ${({ curveAfterHeight }) => curveAfterHeight};
41
+ background: ${({ curveAfterBackgroundColor }) => curveAfterBackgroundColor};
42
+ width: ${({ curveAfterWidth }) => curveAfterWidth};
43
+ }
44
+ `
45
+
46
+ const Ribbon = ({
47
+ children,
48
+ tokens,
49
+ wrap: shouldWrap = false,
50
+ left,
51
+ top,
52
+ variant = {},
53
+ ...rest
54
+ }) => {
55
+ const {
56
+ backgroundColor,
57
+ borderRadius,
58
+ boxShadowPaddingBottom,
59
+ boxShadowPaddingLeft,
60
+ boxShadowPaddingRight,
61
+ boxShadowPaddingTop,
62
+ boxShadowColor,
63
+ curveAfterBackgroundColor,
64
+ curveAfterHeight,
65
+ curveAfterWidth,
66
+ curveBackgroundColor,
67
+ curveHeight,
68
+ curveAfterRadius,
69
+ curveWidth,
70
+ curveMarginTop,
71
+ paddingBottom,
72
+ paddingLeft,
73
+ paddingRight,
74
+ paddingTop,
75
+ gradient
76
+ } = useThemeTokens('Ribbon', tokens, variant)
77
+
78
+ const { purpose } = variant
79
+ const { type: gradientType, angle: gradientAngle, stops: gradientColors } = gradient
80
+ const isOfferPurpose = purpose === 'offer'
81
+ const gradientBackground = `${gradientType}-gradient(${gradientAngle}deg, ${gradientColors[0].color}, ${gradientColors[1].color})`
82
+ const background = isOfferPurpose ? gradientBackground : backgroundColor
83
+
84
+ return (
85
+ <RibbonWrapper left={left} top={top} data-testid="ribbon-wrapper" {...selectProps(rest)}>
86
+ <RibbonContainer
87
+ shouldWrap={shouldWrap}
88
+ backgroundColor={background}
89
+ padding={`${paddingTop}px ${paddingRight}px ${paddingBottom}px ${paddingLeft}px`}
90
+ borderRadius={`${borderRadius}px`}
91
+ boxShadow={`${boxShadowPaddingTop}px ${boxShadowPaddingRight}px ${boxShadowPaddingBottom}px ${boxShadowPaddingLeft}px ${boxShadowColor}`}
92
+ >
93
+ <Typography variant={{ size: 'micro', bold: true, inverse: true }}>{children}</Typography>
94
+ </RibbonContainer>
95
+ {shouldWrap && (
96
+ <RibbonCurve
97
+ data-testid="ribbon-curve"
98
+ backgroundColor={backgroundColor}
99
+ curveMarginTop={`${curveMarginTop}px`}
100
+ curveWidth={`${curveWidth}px`}
101
+ curveHeight={`${curveHeight}px`}
102
+ curveBackgroundColor={curveBackgroundColor}
103
+ curveAfterRadius={`${curveAfterRadius}px`}
104
+ curveAfterWidth={`${curveAfterWidth}px`}
105
+ curveAfterHeight={`${curveAfterHeight}px`}
106
+ curveAfterBackgroundColor={curveAfterBackgroundColor}
107
+ />
108
+ )}
109
+ </RibbonWrapper>
110
+ )
111
+ }
112
+
113
+ Ribbon.propTypes = {
114
+ ...selectedSystemPropTypes,
115
+ children: PropTypes.node,
116
+ /** show/hide the ribbon fold
117
+ * @deprecated please don't rely on `wrap` to turn off the wrapping (use `Badge` instead) as it will be removed in the future
118
+ */
119
+ wrap: PropTypes.bool,
120
+ /** sets the left offset (triggers absolute positioning) */
121
+ left: PropTypes.number,
122
+ /** sets the top offset (triggers absolute positioning) */
123
+ top: PropTypes.number
124
+ }
125
+
126
+ export default Ribbon
@@ -0,0 +1,3 @@
1
+ import Ribbon from './Ribbon'
2
+
3
+ export default Ribbon
package/src/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export { default as Badge } from './Badge'
2
+ export { default as OrderedList } from './OrderedList'
3
+ export { default as Ribbon } from './Ribbon'
2
4
  export { transformGradient } from './utils'
3
5
 
4
6
  export * from './baseExports'
@@ -0,0 +1,14 @@
1
+ import type { ComponentType, ReactNode } from 'react'
2
+ import type { HTMLAttrs, Variant } from './common'
3
+
4
+ export interface RibbonProps extends HTMLAttrs {
5
+ children?: ReactNode
6
+ variant?: Variant
7
+ left: Boolean
8
+ top: Boolean
9
+ wrap: Boolean
10
+ }
11
+
12
+ declare const Ribbon: ComponentType<RibbonProps>
13
+
14
+ export default Ribbon