Skip to content
Closed
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
3 changes: 2 additions & 1 deletion packages/components/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IBtnProps extends React.ButtonHTMLAttributes<HTMLElement> {
small?: boolean
large?: boolean
showIconOnly?: boolean
iconColor?: string
}

type ToArray<Type> = [Type] extends [any] ? Type[] : never
Expand Down Expand Up @@ -112,7 +113,7 @@ export const Button = (props: BtnProps) => {
pointerEvents: 'none',
}}
>
<Icon glyph={props.icon} />
<Icon glyph={props.icon} color={props.iconColor} />
</Flex>
)}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion following issue above: here you should use sx to so that you can access the theme colors directly. Eg: <Icon glyph={props.icon} sx={{ color: props.iconColor }} />

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had to add sx to the IconWrapper Component directly, as it uses styled components, which didn't seem to work well with the theming I had defined.

<Text
Expand Down
11 changes: 9 additions & 2 deletions packages/components/src/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @jsxImportSource theme-ui */
import styled from '@emotion/styled'
import type { VerticalAlignProps, SpaceProps } from 'styled-system'
import { verticalAlign, space } from 'styled-system'
Expand Down Expand Up @@ -40,6 +41,7 @@ import { iconMap } from './svgs'
import { DownloadIcon } from './DownloadIcon'
import { ExternalUrl } from './ExternalUrl'
import type { IGlyphs } from './types'
import type { ThemeUIStyleObject } from 'theme-ui'

interface IGlyphProps {
glyph: keyof IGlyphs
Expand All @@ -51,6 +53,7 @@ export interface IProps {
marginRight?: string
color?: string
onClick?: () => void
sx?: ThemeUIStyleObject
}

export const glyphs: IGlyphs = {
Expand Down Expand Up @@ -115,7 +118,6 @@ const IconWrapper = styled.div<Props>`
min-width: ${(props) => (props.size ? `${props.size}px` : '32px')};
min-height: ${(props) => (props.size ? `${props.size}px` : '32px')};
position: relative;
color: ${(props) => (props.color ? `${props.color}` : 'inherit')};
${verticalAlign}
${space}

Expand Down Expand Up @@ -153,7 +155,12 @@ export const Icon = (props: Props) => {
}

return (
<IconWrapper {...props} size={definedSize} style={{ marginRight }}>
<IconWrapper
{...props}
sx={{ color: props.color ? `${props.color}` : 'inherit' }}
size={definedSize}
style={{ marginRight }}
>
<IconContext.Provider
value={{
style: { width: definedSize + 'px', height: definedSize + 'px' },
Expand Down
21 changes: 21 additions & 0 deletions packages/themes/src/common/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const commonColors = {
white: 'white',
offwhite: '#ececec',
black: '#1b1b1b',
softyellow: '#f5ede2',
blue: '#83ceeb',
red: '#eb1b1f',
red2: '#f58d8e',
softblue: '#e2edf7',
bluetag: '#5683b0',
grey: '#61646b',
green: '#00c3a9',
error: 'red',
background: '#f4f6f7',
silver: '#c0c0c0',
softgrey: '#c2d4e4',
lightgrey: '#ababac',
darkGrey: '#686868',
subscribed: 'orange',
'not-subscribed': '#1b1b1b',
}
19 changes: 2 additions & 17 deletions packages/themes/src/fixing-fashion/styles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { commonColors } from './../common/colors'
import type { ThemeWithName } from '../types'
import spaceBadge from '../../assets/images/themes/fixing-fashion/avatar_space_lg.svg'
import memberBadgeLowDetail from '../../assets/images/themes/fixing-fashion/avatar_member_sm.svg'
Expand All @@ -12,25 +13,9 @@ const fonts = {

// use enum to specify list of possible colors for typing
export const colors = {
white: 'white',
offwhite: '#ececec',
black: '#1b1b1b',
...commonColors,
primary: 'green',
softyellow: '#f5ede2',
yellow: { base: '#E95628', hover: 'hsl(14, 81%, 43%)' },
blue: '#83ceeb',
red: '#eb1b1f',
red2: '#f58d8e',
softblue: '#e2edf7',
bluetag: '#5683b0',
grey: '#61646b',
green: '#00c3a9',
error: 'red',
background: '#f4f6f7',
silver: '#c0c0c0',
softgrey: '#c2d4e4',
lightgrey: '#ababac',
darkGrey: '#686868',
}

export const zIndex = {
Expand Down
19 changes: 2 additions & 17 deletions packages/themes/src/precious-plastic/styles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { commonColors } from './../common/colors'
import memberBadgeLowDetail from '../../assets/images/themes/precious-plastic/avatar_member_sm.svg'
import memberBadgeHighDetail from '../../assets/images/themes/precious-plastic/avatar_member_lg.svg'
import CollectionBadge from '../../assets/images/badges/pt-collection-point.svg'
Expand All @@ -20,25 +21,9 @@ const fonts = {

// use enum to specify list of possible colors for typing
export const colors = {
white: 'white',
offwhite: '#ececec',
black: '#1b1b1b',
...commonColors,
primary: 'red',
softyellow: '#f5ede2',
yellow: { base: '#fee77b', hover: '#ffde45' },
blue: '#83ceeb',
red: '#eb1b1f',
red2: '#f58d8e',
softblue: '#e2edf7',
bluetag: '#5683b0',
grey: '#61646b',
green: '#00c3a9',
error: 'red',
background: '#f4f6f7',
silver: '#c0c0c0',
softgrey: '#c2d4e4',
lightgrey: '#ababac',
darkGrey: '#686868',
}

export const zIndex = {
Expand Down
19 changes: 2 additions & 17 deletions packages/themes/src/project-kamp/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,14 @@ import memberBadgeHighDetail from '../../assets/images/themes/project-kamp/avata
import logo from '../../assets/images/themes/project-kamp/project-kamp-header.png'
import type { ThemeWithName } from '../types'
import { getButtons } from '../common/button'
import { commonColors } from '../common/colors'
export type { ButtonVariants } from '../common/button'

// use enum to specify list of possible colors for typing
export const colors = {
white: 'white',
offwhite: '#ececec',
black: '#1b1b1b',
...commonColors,
primary: 'green',
softyellow: '#f5ede2',
yellow: { base: '#8ab57f', hover: 'hsl(108, 25%, 68%)' },
blue: '#83ceeb',
red: '#eb1b1f',
red2: '#f58d8e',
softblue: '#e2edf7',
bluetag: '#5683b0',
grey: '#61646b',
green: '#00c3a9',
error: 'red',
background: '#f4f6f7',
silver: '#c0c0c0',
softgrey: '#c2d4e4',
lightgrey: '#ababac',
darkGrey: '#686868',
}

export const zIndex = {
Expand Down
2 changes: 2 additions & 0 deletions packages/themes/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface ThemeWithName {
offwhite: string
lightgrey: string
darkGrey: string
subscribed: string
'not-subscribed': string
}

fontSizes: number[]
Expand Down
43 changes: 41 additions & 2 deletions src/pages/Research/Content/ResearchArticle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
FactoryResearchItemUpdate,
} from 'src/test/factories/ResearchItem'
import { preciousPlasticTheme } from 'oa-themes'
import ResearchArticle from './ResearchArticle'
import { FactoryUser } from 'src/test/factories/User'

const Theme = preciousPlasticTheme.styles

jest.mock('src/index', () => ({
Expand All @@ -28,7 +31,9 @@ jest.mock('src/index', () => ({

jest.mock('src/stores/Research/research.store')

import ResearchArticle from './ResearchArticle'
const activeUser = FactoryUser({
userRoles: ['beta-tester'],
})

describe('Research Article', () => {
const mockResearchStore = {
Expand Down Expand Up @@ -75,6 +80,36 @@ describe('Research Article', () => {
expect(wrapper.getAllByText('another-example-username')).toHaveLength(1)
})

it('displays "Follow" button text if not subscribed', async () => {
// Arrange
;(useResearchStore as jest.Mock).mockReturnValue({
...mockResearchStore,
})

// Act
const wrapper = getWrapper()

// Assert
expect(wrapper.getAllByText('Follow').length).toBeGreaterThan(0)
})

it('displays "Following" button text if user is subscribed', async () => {
// Arrange
;(useResearchStore as jest.Mock).mockReturnValue({
...mockResearchStore,
activeResearchItem: FactoryResearchItem({
subscribers: [activeUser.userName],
}),
activeUser,
})

// Act
const wrapper = getWrapper()

// Assert
expect(wrapper.getAllByText('Following').length).toBeGreaterThan(0)
})

describe('Research Update', () => {
it('displays contributors', async () => {
// Arrange
Expand Down Expand Up @@ -147,7 +182,11 @@ describe('Research Article', () => {

const getWrapper = () => {
return render(
<Provider userStore={{}}>
<Provider
userStore={{
user: activeUser,
}}
>
<ThemeProvider theme={Theme}>
<MemoryRouter initialEntries={['/research/article']}>
<Route
Expand Down
17 changes: 11 additions & 6 deletions src/pages/Research/Content/ResearchDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** @jsxImportSource theme-ui */
import { useTheme } from '@emotion/react'
import { format } from 'date-fns'
import {
Button,
Expand All @@ -14,9 +16,6 @@ import { isUserVerified } from 'src/common/isUserVerified'
import type { IResearch } from 'src/models/research.models'
import type { IUser } from 'src/models/user.models'
import { useResearchStore } from 'src/stores/Research/research.store'
// TODO: Remove direct usage of Theme
import { preciousPlasticTheme } from 'oa-themes'
const theme = preciousPlasticTheme.styles
import {
addIDToSessionStorageArray,
retrieveSessionStorageArray,
Expand Down Expand Up @@ -48,6 +47,7 @@ const ResearchDescription = ({ research, isEditable, ...props }: IProps) => {
let didInit = false
const store = useResearchStore()
const [viewCount, setViewCount] = useState<number | undefined>()
const theme = useTheme()

const incrementViewCount = async () => {
const sessionStorageArray = retrieveSessionStorageArray('research')
Expand Down Expand Up @@ -110,14 +110,19 @@ const ResearchDescription = ({ research, isEditable, ...props }: IProps) => {
<Button
icon="thunderbolt"
variant="outline"
iconColor={
research.subscribers?.includes(
props?.loggedInUser?.userName || '',
)
? theme.colors.subscribed
: theme.colors['not-subscribed']
}
Copy link
Copy Markdown
Contributor

@AlfonsoGhislieri AlfonsoGhislieri Apr 25, 2023

Choose a reason for hiding this comment

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

Issue: Would be a lot cleaner to not have these colors hardcoded, would be nicer to add them to the theme/use the theme instead (eg: subscribed: 'orange', not-subscribed: 'black'). You can find the theme files in packages/themes/src.

Let me know if you have any questions or need any help for this. BUT, if this is too much extra work and you don't have time I'm happy to approve this and add it to my TODO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

sx={{
fontSize: 2,
py: 0,
height: '41.5px', // TODO: Ideally this is a standard size
}}
onClick={() => {
props.onFollowingClick()
}}
onClick={props.onFollowingClick}
>
{research.subscribers?.includes(
props?.loggedInUser?.userName || '',
Expand Down