-
Notifications
You must be signed in to change notification settings - Fork 367
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
style: [M3-6639] - Add outline to country flags that contain white #9288
Merged
bnussman-akamai
merged 7 commits into
linode:develop
from
bnussman-akamai:M3-6639-add-flag-outline
Jun 23, 2023
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c8b6958
add outline for some lags and add Flag story
bnussman e4838c1
make type respect what the Linode API returns
bnussman 1912f7e
Added changeset: Outline to some country flags
bnussman a4d0277
use `styled`
bnussman 048a55e
only add outline in light mode
bnussman 8b8d9ac
use boxShadow
bnussman 9ee9890
Merge branch 'develop' into M3-6639-add-flag-outline
bnussman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Added | ||
--- | ||
|
||
Outline to some country flags ([#9288](https://github.com/linode/manager/pull/9288)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { Flag } from './Flag'; | ||
|
||
const meta: Meta<typeof Flag> = { | ||
title: 'Components/Flag', | ||
component: Flag, | ||
}; | ||
|
||
type Story = StoryObj<typeof Flag>; | ||
|
||
export const Default: Story = { | ||
render: (args) => <Flag {...args} />, | ||
args: { | ||
country: 'us', | ||
}, | ||
}; | ||
|
||
export default meta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
import React from 'react'; | ||
import 'flag-icons/css/flag-icons.min.css'; | ||
import { Country } from './EnhancedSelect/variants/RegionSelect/utils'; | ||
import { styled } from '@mui/material/styles'; | ||
import { isPropValid } from 'src/utilities/isPropValid'; | ||
|
||
const countryFlagOverrides = { | ||
const COUNTRY_FLAG_OVERRIDES = { | ||
uk: 'gb', | ||
}; | ||
|
||
const COUNTRIES_TO_OUTLINE = ['jp', 'id', 'sg']; | ||
|
||
interface Props { | ||
/** expects a iso code of a country - `us`, `ca`, etc... */ | ||
country: string; | ||
country: Lowercase<Country>; | ||
} | ||
|
||
/** | ||
* Flag icons are provided by the [flag-icons](https://www.npmjs.com/package/flag-icon) package | ||
*/ | ||
export const Flag = (props: Props) => { | ||
const country = props.country.toLowerCase(); | ||
|
||
return ( | ||
<div | ||
className={`fi fi-${countryFlagOverrides[country] ?? country} fi-xx`} | ||
style={{ fontSize: '1.5rem', verticalAlign: 'top' }} | ||
<StyledFlag | ||
className={`fi fi-${COUNTRY_FLAG_OVERRIDES[country] ?? country} fi-xx`} | ||
hasOutline={COUNTRIES_TO_OUTLINE.includes(country)} | ||
/> | ||
); | ||
}; | ||
|
||
const StyledFlag = styled('div', { | ||
label: 'StyledFlag', | ||
shouldForwardProp: (prop) => isPropValid(['hasOutline'], prop), | ||
})<{ hasOutline: boolean }>(({ theme, ...props }) => ({ | ||
fontSize: '1.5rem', | ||
outline: props.hasOutline ? `1px solid ${theme.color.border3}` : 'none', | ||
verticalAlign: 'top', | ||
width: '1.41rem', | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
as
is unfortunate but it lets us maintain the typesafety of<Flag />
's props, which I think is more preferable... This also enables the storybook story to auto generate the country options.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just have country defined as
Country
in theRegions
type? https://github.com/linode/manager/blob/develop/packages/api-v4/src/regions/types.ts#L24There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This crossed my mind. We could but we'd have to copy over all of the country data to the api-v4 package, which I'm not sure we should do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also feel like that's where it belongs (rather than defined in the manager package) but this could be a follow up discussion/task
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. What I don't know is if would it be appropriate to list all 243 countries as a possible response from the API. I guess we'd have to