diff --git a/cypress/integration/Avatar.spec.ts b/cypress/integration/Avatar.spec.ts index fd15abe0b6..787a353e15 100644 --- a/cypress/integration/Avatar.spec.ts +++ b/cypress/integration/Avatar.spec.ts @@ -5,9 +5,9 @@ describe('Avatar', () => { h.stories.visit(); }); - context('given default avatar light is rendered', () => { + context('given default avatar is rendered', () => { beforeEach(() => { - h.stories.load('Components/Indicators/Avatar/Default', 'Light'); + h.stories.load('Components/Indicators/Avatar', 'Basic'); }); it('should not have any axe errors', () => { @@ -17,7 +17,7 @@ describe('Avatar', () => { context('given avatar button light is rendered', () => { beforeEach(() => { - h.stories.load('Components/Indicators/Avatar Button/Default', 'Light'); + h.stories.load('Components/Indicators/Avatar', 'Button'); }); it('should not have any axe errors', () => { @@ -27,7 +27,7 @@ describe('Avatar', () => { context('given avatar button image is rendered', () => { beforeEach(() => { - h.stories.load('Components/Indicators/Avatar/Avatar Button', 'Image'); + h.stories.load('Components/Indicators/Avatar/Avatar', 'Image'); }); it('should not have any axe errors', () => { diff --git a/cypress/integration/SelectPreview.spec.ts b/cypress/integration/SelectPreview.spec.ts deleted file mode 100644 index 353733ceee..0000000000 --- a/cypress/integration/SelectPreview.spec.ts +++ /dev/null @@ -1,964 +0,0 @@ -import * as h from '../helpers'; - -function getAssistiveFocus($menu: JQuery): JQuery { - const activeId = $menu.attr('aria-activedescendant'); - return $menu.find(`[id="${activeId}"]`); -} - -function assertOptionInView($option: JQuery) { - const option = $option[0]; - const $menu = $option.parent(); - const menu = $menu[0]; - - const menuBorderTopWidth = parseInt($menu.css('borderTopWidth'), 10); - - const menuViewTop = menu.scrollTop + menuBorderTopWidth; - const menuViewBottom = menuViewTop + menu.clientHeight; - const optionTop = option.offsetTop; - const optionBottom = optionTop + option.offsetHeight; - - const optionInView = optionTop >= menuViewTop && optionBottom <= menuViewBottom; - - expect(optionInView).to.equal(true); -} - -function assertOptionCenteredInView($option: JQuery) { - const option = $option[0]; - const $menu = $option.parent(); - const menu = $menu[0]; - - const menuBorderTopWidth = parseInt($menu.css('borderTopWidth'), 10); - - const expectedMenuScrollTop = Math.floor( - option.offsetTop - menu.clientHeight / 2 - menuBorderTopWidth + option.clientHeight / 2 - ); - - expect(menu.scrollTop).to.equal(expectedMenuScrollTop); -} - -describe('Select', () => { - before(() => { - h.stories.visit(); - }); - ['Default', 'Alert', 'Error'].forEach(story => { - context(`given the "${story}" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Preview/Select/Top Label', story); - }); - - it('should not have any axe errors', () => { - cy.checkA11y(); - }); - - context('when the select button is clicked', () => { - beforeEach(() => { - cy.findByLabelText('Label').click(); - }); - - it('should not have any axe errors', () => { - cy.checkA11y(); - }); - - context('the select button', () => { - it('should have an aria-expanded attribute set to "true"', () => { - cy.findByLabelText('Label').should('have.attr', 'aria-expanded', 'true'); - }); - }); - - context('the menu', () => { - it('should be visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('be.visible'); - }); - - it('should have focus', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('be.focused'); - }); - - it('should have an aria-activedescendant attribute with the same value as the id of the first option ("E-mail")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should($menu => { - const menuAD = $menu.attr('aria-activedescendant'); - const optionId = $menu.find(`[role=option]:eq(0)`).attr('id'); - - expect(menuAD).to.equal(optionId); - }); - }); - - it('should set assistive focus to the first option ("E-mail")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - - context('the first option ("Mail")', () => { - it('should have an aria-selected attribute set to "true"', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getOption(0)) - .should('have.attr', 'aria-selected', 'true'); - }); - }); - - context(`when the "Phone" option (with the value "phone") is clicked`, () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getOption('Phone')) - .click(); - }); - - context('the select button', () => { - it(`should read "Phone"`, () => { - cy.findByLabelText('Label').should('have.text', 'Phone'); - }); - - it(`should have a value of "phone"`, () => { - cy.findByLabelText('Label').should('have.value', 'phone'); - }); - - it(`should re-acquire focus`, () => { - cy.findByLabelText('Label').should('be.focused'); - }); - }); - - context('the menu', () => { - it('should not be visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('not.exist'); - }); - }); - - context('when the menu is opened again', () => { - beforeEach(() => { - cy.findByLabelText('Label').click(); - }); - - context('the menu', () => { - it('should set assistive focus to the "Phone" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Phone'); - }); - }); - - context('the "Phone" option', () => { - it('should have an aria-selected attribute set to "true"', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getOption('Phone')) - .should('have.attr', 'aria-selected', 'true'); - }); - }); - }); - }); - }); - - context('when the select button is focused', () => { - beforeEach(() => { - cy.findByLabelText('Label').focus(); - }); - - context('when the down arrow key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the select button', () => { - it('should have an aria-expanded attribute set to "true"', () => { - cy.findByLabelText('Label').should('have.attr', 'aria-expanded', 'true'); - }); - }); - - context('the menu', () => { - it('should be visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('be.visible'); - }); - - it('should have focus', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('be.focused'); - }); - }); - - context('when the down arrow key is pressed for a second time', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the "Phone" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Phone'); - }); - }); - - context('when the down arrow key is pressed for a third time', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the "Mail" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mail'); - }); - }); - - context('when the enter key is pressed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('{enter}'); - }); - - context('the select button', () => { - it(`should read "Mail"`, () => { - cy.findByLabelText('Label').should('have.text', 'Mail'); - }); - - it(`should have a value of "mail"`, () => { - cy.findByLabelText('Label').should('have.value', 'mail'); - }); - - it(`should re-acquire focus`, () => { - cy.findByLabelText('Label').should('be.focused'); - }); - }); - - context('the menu', () => { - it('should not be visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('not.exist'); - }); - }); - - context('when the menu is expanded again', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the "Mail" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mail'); - }); - }); - - context('the "Mail" option', () => { - it('should have an aria-selected attribute set to "true"', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getOption('Mail')) - .should('have.attr', 'aria-selected', 'true'); - }); - }); - }); - }); - }); - - context('when the up arrow key is pressed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('{uparrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the "E-mail" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - }); - }); - }); - - context('when the enter key is pressed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('{enter}'); - }); - - context('the select button', () => { - it('should have an aria-expanded attribute set to "true"', () => { - cy.findByLabelText('Label').should('have.attr', 'aria-expanded', 'true'); - }); - }); - }); - - context('when the space key is pressed', () => { - beforeEach(() => { - cy.findByLabelText('Label').type(' ', {force: true}); // disable event.preventDefault checks - }); - - context('the select button', () => { - it('should have an aria-expanded attribute set to "true"', () => { - cy.findByLabelText('Label').should('have.attr', 'aria-expanded', 'true'); - }); - }); - }); - }); - - context('when the "select" helper is used to select "Mail"', () => { - beforeEach(() => { - cy.findByLabelText('Label').pipe(h.selectPreview.select('Mail')); - }); - - it('should have a value of "mail"', () => { - cy.findByLabelText('Label').should('have.value', 'mail'); - }); - }); - - context('when the "select" helper is used to select /^Mail$/', () => { - beforeEach(() => { - cy.findByLabelText('Label').pipe(h.selectPreview.select(/^Mail$/)); - }); - - it('should have a value of "mail"', () => { - cy.findByLabelText('Label').should('have.value', 'mail'); - }); - }); - }); - }); - - context(`given the "Default" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Preview/Select/Top Label', 'Default'); - }); - - context('when the menu is opened', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .focus() - .realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the first option ("E-mail")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - - context('when focus is advanced to the second option ("Phone")', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the second option ("Phone")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Phone'); - }); - }); - - context( - 'when the menu is closed WITHOUT selecting the newly focused option ("Phone")', - () => { - beforeEach(() => { - cy.focused().realType('{esc}'); - }); - - context('when the menu is re-opened AFTER it has fully closed', () => { - beforeEach(() => { - // Wait for menu to fully close before we open it again (so we - // don't interrupt the menu's closing animation and cause it to - // re-open while it's in the middle of closing) - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .should('not.exist'); - cy.findByLabelText('Label') - .focus() - .realType('{downarrow}'); - }); - - context('the menu', () => { - it('should have reset assistive focus to the first option ("E-mail")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - }); - - context('when the menu is re-opened BEFORE it has fully closed', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should still have assistive focus set to the second option ("Phone")', () => { - // Focus is shifting between the button and menu as we close - // and open the menu. It's important that we use getMenu rather - // than cy.focused() to ensure we obtain a reference to the menu. - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Phone'); - }); - }); - }); - } - ); - }); - }); - }); - - context(`given the "Disabled" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Preview/Select/Top Label', 'Disabled'); - }); - - it('should not have any axe errors', () => { - cy.checkA11y(); - }); - - context('the select button', () => { - it('should be disabled', () => { - cy.findByLabelText('Label').should('be.disabled'); - }); - }); - }); - - context('given the "Disabled Options Test" story is rendered', () => { - beforeEach(() => { - h.stories.load('Testing/Preview/Select/Cypress', 'Disabled Options Test'); - }); - - context('when the menu is opened', () => { - beforeEach(() => { - cy.findByLabelText('Label (Disabled Options)') - .focus() - .realType('{downarrow}'); - }); - - context('the "Carrier Pigeon" option', () => { - it('should have an aria-disabled attribute set to "true"', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getOption('Carrier Pigeon')) - .should('have.attr', 'aria-disabled', 'true'); - }); - }); - - context('when the down arrow key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to first enabled option ("E-mail")', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - - context('when the up arrow key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{uparrow}'); - }); - - context('the menu', () => { - it('should retain assistive focus on the "E-mail" option since the previous option ("Carrier Pigeon", which also happens to be the first option) is disabled', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - }); - - context('when the down arrow key is pressed 2 more times', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the third option down ("Mail") since focus will have skipped one disabled option ("Fax")', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mail'); - }); - }); - - context('when the down arrow key is pressed 2 more times', () => { - beforeEach(() => { - cy.focused().realType('{downarrow}{downarrow}'); - }); - - context('the menu', () => { - it('should set assistive focus to the first option down ("Mobile Phone") since the second option down ("Telegram", which also happens to be the last option) is disabled', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mobile Phone'); - }); - }); - }); - }); - }); - - context('when the Home key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{home}'); - }); - - context('the menu', () => { - it('should set assistive focus to the first enabled option ("E-mail")', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'E-mail'); - }); - }); - }); - - context('when the End key is pressed', () => { - beforeEach(() => { - cy.focused().realType('{end}'); - }); - - context('the menu', () => { - it('should set assistive focus to the last enabled option ("Mobile Phone")', () => { - cy.findByLabelText('Label (Disabled Options)') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Mobile Phone'); - }); - }); - }); - }); - }); - - context(`given the "Scrollable" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Preview/Select/Top Label', 'Scrollable'); - }); - - context('when the select button is focused', () => { - beforeEach(() => { - cy.findByLabelText('Label').focus(); - }); - - context( - 'when a character is typed (provided no other characters have been typed in the last 500ms), the select should select the first matching option beyond the currently selected option (cycling back to the beginning of the options if necessary)', - () => { - context('when "s" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('s'); - }); - - context('the select button', () => { - it('should read the first option beginning with "s" ("San Francisco (United States)")', () => { - cy.findByLabelText('Label').should('have.text', 'San Francisco (United States)'); - }); - - it(`should have a value of "san-francisco"`, () => { - cy.findByLabelText('Label').should('have.value', 'san-francisco'); - }); - }); - }); - - context('when "s{500ms delay}s" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('ss', {delay: 500}); - }); - - context('the select button', () => { - it('should read the second option beginning with "s" ("San Mateo (United States)")', () => { - cy.findByLabelText('Label').should('have.text', 'San Mateo (United States)'); - }); - }); - }); - - context('when "s{500ms delay}d" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('sd', {delay: 500}); - }); - - context('the select button', () => { - it('should read the first option beginning with "d" ("Dallas (United States)")', () => { - cy.findByLabelText('Label').should('have.text', 'Dallas (United States)'); - }); - }); - }); - } - ); - - context( - 'when multiple characters are typed in rapid succession (<500ms between keystrokes), thus forming a string, and multiple options begin with that string, the select should retain the currently selected option for as long as possible (instead of cycling selection between matching options with each keystroke)', - () => { - context('when "sa" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('sa'); - }); - - context('the select button', () => { - it('should read "San Francisco (United States)"', () => { - cy.findByLabelText('Label').should('have.text', 'San Francisco (United States)'); - }); - }); - }); - - context('when "san " is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('san '); - }); - - context('the select button', () => { - it('should read "San Francisco (United States)"', () => { - cy.findByLabelText('Label').should('have.text', 'San Francisco (United States)'); - }); - }); - }); - - context('when "san m" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label').realType('san m'); - }); - - context('the select button', () => { - it('should read "San Mateo (United States)"', () => { - cy.findByLabelText('Label').should('have.text', 'San Mateo (United States)'); - }); - }); - }); - } - ); - - // TODO: Figure out why this test doesn't open the menu when the - // space key is pressed when using Firefox with Cypress (pressing - // the space key in the middle of a typeahead string in normal - // usage of Firefox opens the menu, see SelectBase) - // Ensure Firefox doesn't display the menu if there's a space in the - // typeahead string - // context('when "san " is typed', () => { - // beforeEach(() => { - // cy.findByLabelText('Label').realType('san '); - // }); - - // context('the menu', () => { - // it('should not be visible', () => { - // cy.findByLabelText('Label') - // .pipe(h.selectPreview.getMenu) - // .should('not.exist'); - // }); - // }); - // }); - }); - - context('when the menu is opened', () => { - beforeEach(() => { - cy.findByLabelText('Label').click(); - }); - - context( - 'when a character is typed (provided no other characters have been typed in the last 500ms), the select should advance assistive focus to the first matching option beyond the currently selected option (cycling back to the beginning of the options if necessary) and scroll that option into view', - () => { - context('when "s" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('s'); - }); - - context('the menu', () => { - it('should set assistive focus to the first option beginning with "s" ("San Francisco (United States)")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Francisco (United States)'); - }); - - it('should scroll so that the "San Francisco (United States)" option is fully visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionInView); - }); - }); - }); - - context('when "s{500ms delay}s" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('ss', {delay: 500}); - }); - - context('the menu', () => { - it('should set assistive focus to the second option beginning with "s" ("San Mateo (United States)")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Mateo (United States)'); - }); - - it('should scroll so that the "San Mateo (United States)" option is fully visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionInView); - }); - }); - }); - - context('when "s{500ms delay}d" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('sd', {delay: 500}); - }); - - context('the menu', () => { - it('should set assistive focus to the first option beginning with "d" ("Dallas (United States)")', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'Dallas (United States)'); - }); - - it('should scroll so that the "Dallas (United States)" option is fully visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionInView); - }); - }); - }); - - context('when "the onto" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('the onto'); - }); - - context('the menu', () => { - it('should set assistive focus to "The Ontologically..."', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should( - 'have.text', - 'The Ontologically Anthropocentric Sensory Immersive Simulation (Virtual Reality)' - ); - }); - - it('should scroll so that the "The Ontologically..." (text wrapped) option is fully visible', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionInView); - }); - }); - }); - } - ); - - context( - 'when multiple characters are typed in rapid succession (<500ms between keystrokes), thus forming a string, and multiple options begin with that string, the select should retain assistive focus on the currently focused option for as long as possible (instead of cycling focus between matching options with each keystroke)', - () => { - context('when "sa" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('sa'); - }); - - context('the menu', () => { - it('should set assistive focus to the "San Francisco (United States)" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Francisco (United States)'); - }); - }); - }); - - context('when "san " is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('san '); - }); - - context('the menu', () => { - it('should set assistive focus to the "San Francisco (United States)" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Francisco (United States)'); - }); - }); - }); - - context('when "san m" is typed', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .realType('san m'); - }); - - context('the menu', () => { - it('should set assistive focus to the "San Mateo (United States)" option', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should('have.text', 'San Mateo (United States)'); - }); - }); - }); - } - ); - }); - - context( - 'when the menu is opened and the selected option is initially out of view, the menu should scroll the selected option into view and center it if possible', - () => { - context('when "Dallas (United States)" is selected and the menu is opened', () => { - beforeEach(() => { - cy.findByLabelText('Label') - .focus() - .type('d') - .click(); - }); - - context('the menu', () => { - it('should scroll so that the "Dallas (United States)" option is centered in view', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionCenteredInView); - }); - }); - }); - - context( - 'when "The Ontologically..." (text wrapped) is selected and the menu is opened', - () => { - beforeEach(() => { - cy.findByLabelText('Label') - .focus() - .type('the onto') - .click(); - }); - - context('the menu', () => { - it('should scroll so that the "The Ontologically..." option is centered in view', () => { - cy.findByLabelText('Label') - .pipe(h.selectPreview.getMenu) - .pipe(getAssistiveFocus) - .should(assertOptionCenteredInView); - }); - }); - } - ); - } - ); - }); - - context(`given the "Portal Test" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Testing/Preview/Select/Cypress', 'Portal Test'); - }); - - context('when the page is scrolled to the bottom', () => { - beforeEach(() => { - cy.scrollTo('bottom'); - cy.window() - .its('scrollY') - .as('originalWindowScrollY'); - }); - - context('when the bottommost select button is clicked', () => { - beforeEach(() => { - cy.findByLabelText('Label (Bottom)').click(); - }); - - context('the page', () => { - it('should not scroll', () => { - cy.window().then($window => { - cy.get('@originalWindowScrollY').should('equal', Math.floor($window.scrollY)); - }); - }); - }); - }); - - context( - `when the blur test button is clicked and then the bottommost select button (which is re-rendered by the test button's blur handler) is clicked`, - () => { - beforeEach(() => { - cy.findByTestId('blur-test-button').click(); - cy.findByLabelText('Label (Bottom)').click(); - }); - - context('the page', () => { - it('should not scroll', () => { - cy.window().then($window => { - cy.get('@originalWindowScrollY').should('equal', Math.floor($window.scrollY)); - }); - }); - }); - } - ); - }); - }); - - context(`given the "Accessibility Test" story is rendered`, () => { - beforeEach(() => { - h.stories.load('Testing/Preview/Select/Cypress', 'Accessibility Test'); - }); - - context('when the select button with aria-required set to true is clicked', () => { - beforeEach(() => { - cy.findByLabelText(/Label \(aria-required\)/).click(); - }); - - context('the menu', () => { - it('should have an aria-required attribute set to "true"', () => { - cy.findByLabelText(/Label \(aria-required\)/) - .pipe(h.selectPreview.getMenu) - .should('have.attr', 'aria-required', 'true'); - }); - }); - }); - - context('when the select button with required set to true is clicked', () => { - beforeEach(() => { - cy.findByLabelText(/Label \(required\)/).click(); - }); - - context('the menu', () => { - it('should have an aria-required attribute set to "true"', () => { - cy.findByLabelText(/Label \(required\)/) - .pipe(h.selectPreview.getMenu) - .should('have.attr', 'aria-required', 'true'); - }); - }); - }); - }); -}); diff --git a/modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx b/modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx new file mode 100644 index 0000000000..37ebc92973 --- /dev/null +++ b/modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx @@ -0,0 +1,207 @@ +import {Meta} from '@storybook/addon-docs'; +import {Table} from '@workday/canvas-kit-react/table'; +import {base, brand, system} from '@workday/canvas-tokens-web'; +import {StatusIndicator} from '@workday/canvas-kit-preview-react/status-indicator'; +import {cssVar} from '@workday/canvas-kit-styling'; +import {Box} from '@workday/canvas-kit-react/layout'; + + + +# Canvas Kit 12.0 Upgrade Guide + +This guide contains an overview of the changes in Canvas Kit v12. Please +[reach out](https://github.com/Workday/canvas-kit/issues/new?labels=bug&template=bug.md) if you have +any questions. + +## Why You Should Upgrade + +Canvas Kit v12 is transitioning into a +[new way of styling](https://github.com/Workday/canvas-kit/discussions/2265). Theming and building +an in sync Canvas Kit CSS has been at the top of our minds. We've started using our new +[Canvas Tokens Web](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs) +package to take advantage of +[CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) and +provide semantic tokens that can translate to theming components. + +A note to the reader: + +- While we still support our old tokens from `@workday/canvas-kit-react/tokens` in v12, you must + install our new tokens from `@workday/canvas-tokens-web`. You can find more info in our + [docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs). +- In this release, we've introduced a + [new styling API](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-stencil). + This shouldn't effect the way you currently style your components. Because we're moving away from + Emotion, support for style props will eventually be removed, however, this API provide backwards + compatability. If you want to slowly move off of Emotion as well, you can start styling components + via the `cs` prop or our new styling utilities. + +## Table of contents + +- [Canvas Tokens](#canvas-tokens) +- [Codemod](#codemod) +- [Deprecations](#deprecations) +- [Removals](#removals) + - [InputIconContainer](#inputiconcontainer) + - [Select (Preview)](#select-preview) +- [Component Updates](#component-updates) + - [Styling API and CSS Tokens](#styling-api-and-css-tokens) + - [Avatar](#avatar) + - [Text Area](#text-area) +- [Troubleshooting](#troubleshooting) +- [Glossary](#glossary) + - [Main](#main) + - [Preview](#preview) + - [Labs](#labs) + +## Canvas Tokens + +In v12, all the components listed in this guide have started using our new +[Canvas Tokens Web](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs). + +In v12 you must add `@workday/canvas-tokens-web` to ensure our components are properly styled and +the variables are defined. For more information on installing and using, please reference our tokens +[docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs). + +## Deprecations + +We add the [@deprecated](https://jsdoc.app/tags-deprecated.html) JSDoc tag to code we plan to remove +in a future major release. This signals consumers to migrate to a more stable alternative before the +deprecated code is removed. + +## Removals + +Removals are deletions from our codebase and you can no longer consume this component. We've either +promoted or replaced a component or utility. + +### Select (Preview) + +**PR:** [#2796](https://github.com/Workday/canvas-kit/pull/2796) + +We've removed the `Select` component that was in Preview. Please use the compound +[Select component from Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--basic). + +### InputIconContainer + +**PR:** [#2838](https://github.com/Workday/canvas-kit/pull/2838) + +We've removed `InputIconContainer` from Main. Please use +[InputGroup](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-text-input--icons) +from Main instead. + +--- + +## Component Updates + +### Styling API and CSS Tokens + +**PRs:** [#2825](https://github.com/Workday/canvas-kit/pull/2825), +[#2795](https://github.com/Workday/canvas-kit/pull/2795), +[#2793](https://github.com/Workday/canvas-kit/pull/2793) + +Several components have been refactored to use our new +[Canvas Tokens](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs) and +[styling API](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-modifiers#createstyles-api). +The React interface **has not changed**, but CSS variables are now used for dynamic properties. + +The following components are affected: + +- `Avatar` +- `Dialog` +- `Modal` +- `Popup` +- `TextArea` +- `TextInput` +- `Toast` + +> **Note:** These components also support our new `cs` prop for styling. Learn more about styling +> with `cs` in our +> [documentation](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--cs-prop). + +### Avatar + +- Avatar no longer uses `SystemIconCircle` for sizing. +- `Avatar.Size` is no longer supported. The `size` prop type has change to accept the following: + `"extraExtraLarge" | "extraLarge" | "large" | "medium" | "small" | "extraSmall" | (string{})` +- `Avatar.Variant` is no longer supported. Enum `AvatarVariant` has been removed. The `variant` type + prop now accepts `"dark" | "light"` +- The `as` prop now accepts any element, not just `div`. + +### Text Area + +**PR:** [#2825](https://github.com/Workday/canvas-kit/pull/2825) + +`TextAreaResizeDirection` is no longer a TypeScript enum, but a JavaScript object. This change does +not effect runtime at all, but may cause TypeScript errors if you use `TextAreaResizeDirection` as a +type. + +```tsx +// v11 +interface MyProps { resize?: TextAreaResizeDirection } + +// 12 type ValueOf = T[keyof T]; interface MyProps { resize?: +ValueOf } +``` + +## Troubleshooting + +### My Styles Seem Broken? + +Our components are reliant on our new Canvas Tokens Web package. Be sure you install +`@workday/canvas-tokens-web`. For more information, reference our +[Getting Started docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs) +for this package. + +### Did You Upgrade All Canvas Kit Related Packages? + +In order for all the packages to work in harmony, you must upgrade all Canvas Kit packages to the +same version that you're using, including: + +- `@workday/canvas-kit-react` +- `@workday/canvas-kit-preview-react` +- `@workday/canvas-kit-labs-react` +- `@workday/canvas-kit-styling` +- `@workday/canvas-kit-react-fonts` +- `@workday/canvas-kit-docs` + +## Glossary + +### Main + +Our Main package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-react` has +undergone a full design and a11y review and is approved for use in product. + +Breaking changes to code in Main will only occur during major version updates and will always be +communicated in advance and accompanied by migration strategies. + +--- + +### Preview + +Our Preview package of Canvas Kit tokens, components, and utilities at +`@workday/canvas-kit-preview-react` has undergone a full design and a11y review and is approved for +use in product, but may not be up to the high code standards upheld in the [Main](#main) package. +Preview is analagous to code in beta. + +Breaking changes are unlikely, but possible, and can be deployed to Preview at any time without +triggering a major version update, though such changes will be communicated in advance and +accompanied by migration strategies. + +Generally speaking, our goal is to eventually promote code from Preview to [Main](#main). +Occasionally, a component with the same name will exist in both [Main](#main) and Preview (for +example, see Segmented Control in [Preview](/components/buttons/segmented-control/) and +[Main](https://d2krrudi3mmzzw.cloudfront.net/v8/?path=/docs/components-buttons-segmented-control--basic)). +In these cases, Preview serves as a staging ground for an improved version of the component with a +different API. The component in [Main](#main) will eventually be replaced with the one in Preview. + +--- + +### Labs + +Our Labs package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-labs-react` +has **not** undergone a full design and a11y review. Labs serves as an incubator space for new and +experimental code and is analagous to code in alpha. + +Breaking changes can be deployed to Labs at any time without triggering a major version update and +may not be subject to the same rigor in communcation and migration strategies reserved for breaking +changes in [Preview](#preview) and [Main](#main). import { opacity } from +"@workday/canvas-tokens-web/dist/es6/system" diff --git a/modules/labs-react/expandable/lib/ExpandableAvatar.tsx b/modules/labs-react/expandable/lib/ExpandableAvatar.tsx index d1c867aa4f..7ef10c871f 100644 --- a/modules/labs-react/expandable/lib/ExpandableAvatar.tsx +++ b/modules/labs-react/expandable/lib/ExpandableAvatar.tsx @@ -21,6 +21,6 @@ const StyledAvatar = styled(Avatar)({ export const ExpandableAvatar = createComponent('button')({ displayName: 'Expandable.Avatar', Component: ({altText, ...elemProps}: ExpandableAvatarProps, ref) => { - return ; + return ; }, }); diff --git a/modules/preview-react/divider/stories/examples/Basic.tsx b/modules/preview-react/divider/stories/examples/Basic.tsx index df1fd32eb2..15d4034f48 100644 --- a/modules/preview-react/divider/stories/examples/Basic.tsx +++ b/modules/preview-react/divider/stories/examples/Basic.tsx @@ -94,7 +94,7 @@ interface ProfileCardProps { const ProfileCard = ({id, name, bio}: ProfileCardProps) => (
((elemProps, Element, model) => { +})(({...elemProps}: PillAvatarProps, Element, model) => { return ( - {elemProps.children} - + > ); }); diff --git a/modules/preview-react/select/LICENSE b/modules/preview-react/select/LICENSE deleted file mode 100644 index 5bcbbab3b9..0000000000 --- a/modules/preview-react/select/LICENSE +++ /dev/null @@ -1,51 +0,0 @@ -Apache License, Version 2.0 Apache License Version 2.0, January 2004 - -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. -Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. -Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. -You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: -You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. -Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. -This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. -Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. -In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. -While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -©2020. Workday, Inc. All rights reserved. Workday and the Workday logo are registered trademarks of Workday, Inc. All other brand and product names are trademarks or registered trademarks of their respective holders. - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/modules/preview-react/select/README.md b/modules/preview-react/select/README.md deleted file mode 100644 index dc196ee7e1..0000000000 --- a/modules/preview-react/select/README.md +++ /dev/null @@ -1,236 +0,0 @@ -# Canvas Kit Select (with Canvas-styled Menu) - - - PREVIEW: Beta - This component is in Preview because it has not been converted to a [Compound Component](../../docs/mdx/COMPOUND_COMPONENTS.mdx) yet. - -A Canvas-styled Select with a Canvas-styled menu. This is a -[_controlled_](https://reactjs.org/docs/forms.html#controlled-components) component. - -Undocumented props (`disabled`, `name`, etc.) should behave similarly to how you would expect from a -standard `; -} -``` - -#### Accessible Example - -```tsx -import * as React from 'react'; -import {Select} from '@workday/canvas-kit-preview-react/select'; -import {FormField} from '@workday/canvas-kit-react/form-field'; - -function Example() { - const options = [ - {label: 'E-mail', value: 'email'}, - {label: 'Phone', value: 'phone'}, - {label: 'Fax (disabled)', value: 'fax', disabled: true}, - {label: 'Mail', value: 'mail'}, - ]; - - const [value, setValue] = React.useState('email'); - - const handleChange = event => { - setValue(event.currentTarget.value); - }; - - return ( - - - - ); -} -``` - -#### Example with Custom Options Data - -Each option in `options` may contain a `data` object with any number of key/value pairs. This `data` -object is carried over to the `option` passed into the `renderOption` function where it may then be -used to customize how each option is rendered. - -```tsx -import * as React from 'react'; -import {Select} from '@workday/canvas-kit-preview-react/select'; -import {FormField} from '@workday/canvas-kit-react/form-field'; -import {colors, typeColors} from '@workday/canvas-kit-react/tokens'; -import { - activityStreamIcon, - avatarIcon, - uploadCloudIcon, - userIcon, -} from '@workday/canvas-system-icons-web'; -import {SystemIcon} from '@workday/canvas-kit-react/icon'; - -function Example() { - const options = [ - {value: 'Activity Stream', data: {icon: activityStreamIcon}}, - {value: 'Avatar', data: {icon: avatarIcon}}, - {value: 'Upload Cloud', data: {icon: uploadCloudIcon}}, - {value: 'User', data: {icon: userIcon}}, - ]; - - const renderOption = option => { - const iconColor = option.focused ? typeColors.inverse : colors.blackPepper100; - return ( -
- -
{option.value}
-
- ); - }; - - const [value, setValue] = React.useState('Activity Stream'); - - const handleChange = event => { - setValue(event.currentTarget.value); - }; - - return ( - - -``` - -## Component Props - -### Required - -#### `options: (Option | string)[]` - -> The options of the Select. `options` may be an array of objects or an array of strings. -> -> If `options` is an array of objects, each object must adhere to the `Option` interface: -> -> - `data: object` (optional) -> - `disabled: boolean` (optional) -> - `id: string` (optional, a random `id` will be assigned to the object if one isn't provided) -> - `label: string` (optional, analagous to the text content of an `
-); - -export const PortalTest = () => ( -
- -

- All gray-bordered containers on this page have their overflow set to hidden. Menus are - rendered using portals and should break out of their containers. -

- - {controlComponent()} - -
- -

- Menus should flip upwards automatically if there isn't enough space in the viewport for them - to extend downwards. As you scroll down and space becomes available, the Menu will flip back - downwards. -

- - {controlComponent()} - -
- -

Menus should behave the same with left-labeled FormFields.

- - {controlComponent()} - -
- -

Menus should break out of Modals.

- -
- - - -
-); diff --git a/modules/preview-react/select/stories/stories_visualTesting.tsx b/modules/preview-react/select/stories/stories_visualTesting.tsx deleted file mode 100644 index da85f102b9..0000000000 --- a/modules/preview-react/select/stories/stories_visualTesting.tsx +++ /dev/null @@ -1,172 +0,0 @@ -import * as React from 'react'; -import { - ComponentStatesTable, - permutateProps, - StaticStates, -} from '@workday/canvas-kit-react/testing'; -import {withSnapshotsEnabled, customColorTheme} from '../../../../utils/storybook'; - -import {Select} from '../lib/Select'; -import {SelectBase} from '../lib/SelectBase'; -import {SelectOption} from '../lib/SelectOption'; - -import {options} from './stories'; - -const normalizedOptions = options.map(option => { - return { - data: {}, - disabled: option.disabled || false, - id: option.value, - label: option.label || option.value, - value: option.value, - }; -}); - -export default withSnapshotsEnabled({ - title: 'Testing/Preview/Select', - component: Select, -}); - -export const SelectStates = () => ( - - { - if (props.disabled && !['', 'hover'].includes(props.className)) { - return false; - } - return true; - } - )} - > - {props => ( - + + Choose an option + { + const option = e.currentTarget.value; + if (option === 'Delete') { + model.events.show(); + setValue(''); + } else { + setValue(e.currentTarget.value); + } + }} + /> + + + {item => {item}} + + + + diff --git a/modules/react/popup/lib/Popper.tsx b/modules/react/popup/lib/Popper.tsx index 6d2df121d3..38c25723db 100644 --- a/modules/react/popup/lib/Popper.tsx +++ b/modules/react/popup/lib/Popper.tsx @@ -154,10 +154,8 @@ const OpenPopper = React.forwardRef( enabled: true, phase: 'afterWrite', fn({state}) { - if (placementRef.current !== state.placement) { - setPlacement(state.placement); - onPlacementChange?.(state.placement); - } + setPlacement(state.placement); + onPlacementChange?.(state.placement); }, }; }, [setPlacement, onPlacementChange]); diff --git a/modules/react/popup/lib/PopupBody.tsx b/modules/react/popup/lib/PopupBody.tsx index 1ca9a0da1f..07d7ed3ebb 100644 --- a/modules/react/popup/lib/PopupBody.tsx +++ b/modules/react/popup/lib/PopupBody.tsx @@ -3,10 +3,20 @@ import * as React from 'react'; import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common'; import {Card} from '@workday/canvas-kit-react/card'; import {usePopupModel} from './hooks'; +import {createStencil} from '@workday/canvas-kit-styling'; +import {mergeStyles} from '../../layout'; +import {system} from '@workday/canvas-tokens-web'; + +export const popupBodyStencil = createStencil({ + base: { + overflowY: 'auto', + padding: system.space.x2, + }, +}); export const PopupBody = createSubcomponent('div')({ displayName: 'Popup.Body', modelHook: usePopupModel, })>(elemProps => { - return ; + return ; }); diff --git a/modules/react/popup/lib/PopupCard.tsx b/modules/react/popup/lib/PopupCard.tsx index 5777bbd8a6..62fd030f59 100644 --- a/modules/react/popup/lib/PopupCard.tsx +++ b/modules/react/popup/lib/PopupCard.tsx @@ -1,65 +1,38 @@ import * as React from 'react'; -import {keyframes} from '@emotion/react'; import {Card} from '@workday/canvas-kit-react/card'; -import {space, type} from '@workday/canvas-kit-react/tokens'; +import {space} from '@workday/canvas-kit-react/tokens'; import { - styled, - TransformOrigin, - getTranslateFromOrigin, - StyledType, ExtractProps, - useConstant, createSubcomponent, + getTransformOrigin, } from '@workday/canvas-kit-react/common'; -import {Flex, FlexStyleProps} from '@workday/canvas-kit-react/layout'; +import {FlexStyleProps, mergeStyles} from '@workday/canvas-kit-react/layout'; import {getTransformFromPlacement} from './getTransformFromPlacement'; import {usePopupCard, usePopupModel} from './hooks'; +import {createStencil, createVars, cssVar, keyframes} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; export type FlexAndBoxProps = ExtractProps & FlexStyleProps; export interface PopupCardProps extends FlexAndBoxProps { children?: React.ReactNode; } -const popupAnimation = (transformOrigin: TransformOrigin) => { - const translate = getTranslateFromOrigin(transformOrigin, space.xxs); +const translateVars = createVars('positionX', 'positionY'); - return keyframes` - 0% { - opacity: 0; - transform: translate(${translate.x}px, ${translate.y}px); - } - 100% { - opacity: 1; - transform: translate(0); - } - `; -}; - -const StyledPopupCard = styled(Card)< - StyledType & {width?: number | string; transformOrigin?: TransformOrigin} ->(({transformOrigin, theme}) => { - if (transformOrigin == null) { - return {}; - } - - return { - animation: popupAnimation(transformOrigin), - animationDuration: '150ms', - animationTimingFunction: 'ease-out', - transformOrigin: `${transformOrigin.vertical} ${transformOrigin.horizontal}`, - [theme.canvas.breakpoints.down('s')]: { - animation: popupAnimation({vertical: 'bottom', horizontal: 'center'}), - animationDuration: '150ms', - animationTimingFunction: 'ease-out', - transformOrigin: 'bottom center', - }, - // Allow overriding of animation in special cases - '.wd-no-animation &': { - animation: 'none', - }, - }; +/** + * Keyframe for the dots loading animation. + */ +const fadeIn = keyframes({ + '0%': { + opacity: 1, + transform: `translate(${cssVar(translateVars.positionX)}, ${cssVar(translateVars.positionY)})`, + }, + '100%': { + opacity: 1, + transform: `translate(0)`, + }, }); function getSpace(value?: string | number) { @@ -72,7 +45,7 @@ function getSpace(value?: string | number) { function getMaxHeight(margin?: string | number) { // set the default margin offset to space.xl - let marginOffset: string | number = space.xl; + let marginOffset: string | number = cssVar(system.space.x10); if (margin) { // parse the margin prop @@ -91,33 +64,61 @@ function getMaxHeight(margin?: string | number) { return `calc(100vh - ${marginOffset})`; } +export const popupCardStencil = createStencil({ + vars: { + maxHeight: '', + transformOriginHorizontal: '', + transformOriginVertical: '', + }, + base: ({maxHeight, transformOriginHorizontal, transformOriginVertical}) => ({ + ...system.type.subtext.large, + display: 'flex', + position: 'relative', + maxWidth: `calc(100vw - ${system.space.x8})`, + flexDirection: 'column', + boxShadow: system.depth[5], + minHeight: system.space.zero, + padding: system.space.x6, + maxHeight: maxHeight, + overflowY: 'auto', + animationName: fadeIn, + animationDuration: '150ms', + animationTimingFunction: 'ease-out', + transformOrigin: `${transformOriginVertical} ${transformOriginHorizontal}`, + // Allow overriding of animation in special cases + '.wd-no-animation &': { + animation: 'none', + }, + '@media screen and (max-width: 768px)': { + transformOrigin: 'bottom center', + }, + }), +}); + export const PopupCard = createSubcomponent('div')({ displayName: 'Popup.Card', modelHook: usePopupModel, elemPropsHook: usePopupCard, -})(({children, ...elemProps}, Element, model) => { +})(({children, ref, ...elemProps}, Element, model) => { const transformOrigin = React.useMemo(() => { return getTransformFromPlacement(model.state.placement || 'bottom'); }, [model.state.placement]); + const translate = getTransformOrigin(transformOrigin, cssVar(system.space.x2)); + const cardMaxHeight = getMaxHeight(elemProps.margin); - // As is a Flex that will render an element of `Element` - const As = useConstant(() => Flex.as(Element)); return ( - {children} - + ); }); diff --git a/modules/react/popup/lib/PopupCloseIcon.tsx b/modules/react/popup/lib/PopupCloseIcon.tsx index 2f9d6c6c26..0ad9ed8d46 100644 --- a/modules/react/popup/lib/PopupCloseIcon.tsx +++ b/modules/react/popup/lib/PopupCloseIcon.tsx @@ -3,12 +3,22 @@ import React from 'react'; import {xIcon} from '@workday/canvas-system-icons-web'; import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common'; import {TertiaryButton} from '@workday/canvas-kit-react/button'; -import {space} from '@workday/canvas-kit-react/tokens'; import {usePopupCloseButton, usePopupModel} from './hooks'; +import {createStencil} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; +import {mergeStyles} from '../../layout'; export interface PopupCloseIconProps extends ExtractProps {} +export const popupCloseIconStencil = createStencil({ + base: { + position: 'absolute', + insetInlineEnd: system.space.x1, + top: system.space.x1, + }, +}); + export const PopupCloseIcon = createSubcomponent('button')({ displayName: 'Popup.CloseIcon', modelHook: usePopupModel, @@ -20,10 +30,7 @@ export const PopupCloseIcon = createSubcomponent('button')({ size="medium" icon={xIcon} type="button" - position="absolute" - insetInlineEnd={space.xxxs} - top={space.xxxs} - {...elemProps} + {...mergeStyles(elemProps, popupCloseIconStencil())} /> ); }); diff --git a/modules/react/popup/lib/PopupHeading.tsx b/modules/react/popup/lib/PopupHeading.tsx index 5989ba0dcb..73368229cb 100644 --- a/modules/react/popup/lib/PopupHeading.tsx +++ b/modules/react/popup/lib/PopupHeading.tsx @@ -4,18 +4,28 @@ import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common import {Card} from '@workday/canvas-kit-react/card'; import {usePopupHeading, usePopupModel} from './hooks'; +import {createStencil} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; +import {mergeStyles} from '../../layout'; export interface PopupHeadingProps extends ExtractProps { children?: React.ReactNode; } +export const popupHeadingStencil = createStencil({ + base: { + marginBlockEnd: system.space.x2, + padding: system.space.x2, + }, +}); + export const PopupHeading = createSubcomponent('h2')({ displayName: 'Popup.Heading', modelHook: usePopupModel, elemPropsHook: usePopupHeading, })(({children, ...elemProps}, Element) => { return ( - + {children} ); diff --git a/modules/react/popup/stories/examples/Basic.tsx b/modules/react/popup/stories/examples/Basic.tsx index a1c57964a2..f2ee90103e 100644 --- a/modules/react/popup/stories/examples/Basic.tsx +++ b/modules/react/popup/stories/examples/Basic.tsx @@ -26,7 +26,7 @@ export const Basic = () => { return ( Delete Item - + Delete Item diff --git a/modules/react/select/stories/stories_VisualTesting.tsx b/modules/react/select/stories/stories_VisualTesting.tsx index 637211a33a..8fac077cd4 100644 --- a/modules/react/select/stories/stories_VisualTesting.tsx +++ b/modules/react/select/stories/stories_VisualTesting.tsx @@ -30,10 +30,6 @@ const options = [ const disabledItems = options.filter(item => item.disabled === true).map(item => item.id); export const SelectStates = () => { - const model = useSelectModel({ - items: options, - nonInteractiveIds: disabledItems, - }); return ( { {label: 'Active Hover', value: 'active hover'}, ], disabled: [ - {label: '', value: false}, + {label: '', value: undefined}, {label: 'Disabled', value: true}, ], }, @@ -65,21 +61,15 @@ export const SelectStates = () => { {props => ( Contact - - {model.state.items.length > 0 && ( - - {item => { - return ( - - {item.id} - - ); - }} - - )} + + {item => { + return {item.id}; + }} + @@ -91,11 +81,6 @@ export const SelectStates = () => { }; export const SelectOpenMenuStates = () => { - const model = useSelectModel({ - items: options, - nonInteractiveIds: disabledItems, - initialVisibility: 'visible', - }); return ( { {props => ( Contact - - {!!model.state.items.length && ( - - {item => { - return ( - - {item.id} - - ); - }} - - )} + + {item => { + return {item.id}; + }} + diff --git a/modules/react/side-panel/stories/stories.tsx b/modules/react/side-panel/stories/stories.tsx index 2b69379321..663e582b1b 100644 --- a/modules/react/side-panel/stories/stories.tsx +++ b/modules/react/side-panel/stories/stories.tsx @@ -243,7 +243,7 @@ const Template = props => ( - + diff --git a/modules/react/text-area/lib/TextArea.tsx b/modules/react/text-area/lib/TextArea.tsx index ee79a6a2b0..b765cfe45e 100644 --- a/modules/react/text-area/lib/TextArea.tsx +++ b/modules/react/text-area/lib/TextArea.tsx @@ -1,107 +1,67 @@ import * as React from 'react'; -import { - createComponent, - StyledType, - GrowthBehavior, - ErrorType, - errorRing, - styled, - Themeable, -} from '@workday/canvas-kit-react/common'; -import {borderRadius, inputColors, space, type} from '@workday/canvas-kit-react/tokens'; +import {createComponent, GrowthBehavior, ErrorType} from '@workday/canvas-kit-react/common'; +import {createStencil, calc, handleCsProp} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; +import {textInputStencil} from '@workday/canvas-kit-react/text-input'; +export type ValueOf = T[keyof T]; -export interface TextAreaProps extends Themeable, GrowthBehavior { - /** - * If true, set the TextArea to the disabled state. - * @default false - */ - disabled?: boolean; +export interface TextAreaProps extends GrowthBehavior { /** * The type of error associated with the TextArea (if applicable). */ error?: ErrorType; - /** - * The function called when the TextArea state changes. - */ - onChange?: (e: React.ChangeEvent) => void; - /** - * The placeholder text of the TextArea. - */ - placeholder?: string; - /** - * If true, set the TextArea to read-only. The user will be unable to interact with the TextArea. - * @default false - */ - readOnly?: boolean; /** * The resize constraints of the TextArea. * @default TextArea.ResizeDirection.Both */ - resize?: TextAreaResizeDirection; - /** - * The value of the TextArea. - */ - value?: any; + resize?: ValueOf; } -export enum TextAreaResizeDirection { - None = 'none', - Both = 'both', - Horizontal = 'horizontal', - Vertical = 'vertical', -} +export const TextAreaResizeDirection = { + None: 'none', + Both: 'both', + Horizontal: 'horizontal', + Vertical: 'vertical', +} as const; -const StyledTextArea = styled('textarea')( - ({theme, error}) => ({ - ...type.levels.subtext.large, - border: `1px solid ${inputColors.border}`, - display: 'block', - backgroundColor: inputColors.background, - borderRadius: borderRadius.m, - boxSizing: 'border-box', - minHeight: space.xxl, - minWidth: `calc((${space.xxxl} * 3) + ${space.xl})`, - transition: '0.2s box-shadow, 0.2s border-color', - padding: space.xxs, // Compensate for border - margin: 0, // Fix Safari +export const textAreaStencil = createStencil({ + extends: textInputStencil, + base: { + minHeight: system.space.x16, + minWidth: calc.add(calc.multiply(system.space.x20, 3), system.space.x10), '&::webkit-resizer': { display: 'none', }, - '&::placeholder': { - color: inputColors.placeholder, - }, - '&:hover': { - borderColor: inputColors.hoverBorder, - }, - '&:focus:not([disabled])': { - borderColor: theme.canvas.palette.common.focusOutline, - boxShadow: `inset 0 0 0 1px ${theme.canvas.palette.common.focusOutline}`, - outline: 'none', - }, - '&:disabled': { - backgroundColor: inputColors.disabled.background, - borderColor: inputColors.disabled.border, - color: inputColors.disabled.text, - '&::placeholder': { - color: inputColors.disabled.text, + }, + + modifiers: { + resize: { + both: { + resize: 'both', + }, + horizontal: { + resize: 'horizontal', + }, + vertical: { + resize: 'vertical', + }, + none: { + resize: 'none', }, }, - ...errorRing(error, theme), - }), - - ({resize, grow}) => ({ - width: grow ? '100%' : undefined, - resize: grow ? TextAreaResizeDirection.Vertical : resize, - }) -); + }, + defaultModifiers: { + resize: 'both', + }, +}); export const TextArea = createComponent('textarea')({ displayName: 'TextArea', Component: ( - {resize = TextAreaResizeDirection.Both, grow, ...elemProps}: TextAreaProps, + {resize = TextAreaResizeDirection.Both, grow, error, ...elemProps}: TextAreaProps, ref, Element - ) => , + ) => , subComponents: { ErrorType, ResizeDirection: TextAreaResizeDirection, diff --git a/modules/react/text-input/index.ts b/modules/react/text-input/index.ts index b7565deb6c..194c5dc7da 100644 --- a/modules/react/text-input/index.ts +++ b/modules/react/text-input/index.ts @@ -1,3 +1,2 @@ -export * from './lib/InputIconContainer'; export * from './lib/TextInput'; export {InputGroup, useInputGroupModel} from './lib/InputGroup'; diff --git a/modules/react/text-input/lib/InputIconContainer.tsx b/modules/react/text-input/lib/InputIconContainer.tsx deleted file mode 100644 index 89dbeeb63d..0000000000 --- a/modules/react/text-input/lib/InputIconContainer.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import * as React from 'react'; -import styled from '@emotion/styled'; -import {GrowthBehavior} from '@workday/canvas-kit-react/common'; -import {space} from '@workday/canvas-kit-react/tokens'; -import {SystemIcon} from '@workday/canvas-kit-react/icon'; - -/** - * ### ⚠️ We've deprecated `InputIconContainerProps` from Main because it doesn't handle bidirectionality or icons at the start of an input. ⚠️ - * Please consider using [`InputGroup`](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-text-input--icons) instead. - * @deprecated - */ -export interface InputIconContainerProps extends GrowthBehavior { - icon?: React.ReactElement; -} - -const Container = styled('div')(({grow}) => ({ - display: grow ? 'block' : 'inline-block', - position: 'relative', -})); - -const IconContainer = styled('div')({ - position: 'absolute', - top: space.xxs, - right: space.xxs, -}); - -/** - * ### ⚠️ We've deprecated `InputIconContainer` from Main because it doesn't handle bidirectionality or icons at the start of an input. ⚠️ - * Please consider using [`InputGroup`](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-text-input--icons) instead. - * @deprecated - */ -export const InputIconContainer: React.FunctionComponent< - React.PropsWithChildren -> = ({grow, children, icon}) => ( - - {children} - {icon && {icon}} - -); diff --git a/modules/react/text-input/lib/TextInput.tsx b/modules/react/text-input/lib/TextInput.tsx index 9e8e077ef4..c04aa74ab3 100644 --- a/modules/react/text-input/lib/TextInput.tsx +++ b/modules/react/text-input/lib/TextInput.tsx @@ -1,16 +1,9 @@ import * as React from 'react'; -import { - createComponent, - StyledType, - GrowthBehavior, - ErrorType, - errorRing, - styled, - Themeable, -} from '@workday/canvas-kit-react/common'; -import {borderRadius, inputColors, space, type} from '@workday/canvas-kit-react/tokens'; +import {createComponent, GrowthBehavior, ErrorType} from '@workday/canvas-kit-react/common'; +import {createStencil, cssVar, px2rem, calc, handleCsProp} from '@workday/canvas-kit-styling'; +import {brand, system} from '@workday/canvas-tokens-web'; -export interface TextInputProps extends Themeable, GrowthBehavior { +export interface TextInputProps extends GrowthBehavior { /** * The type of error associated with the TextInput (if applicable). */ @@ -21,74 +14,103 @@ export interface TextInputProps extends Themeable, GrowthBehavior { width?: number | string; } -const StyledTextInput = styled('input')< - Pick & StyledType ->( - { - ...type.levels.subtext.large, - border: `1px solid ${inputColors.border}`, +export const textInputStencil = createStencil({ + vars: { + width: '', + }, + base: ({width}) => ({ + ...system.type.subtext.large, display: 'block', - backgroundColor: inputColors.background, - borderRadius: borderRadius.m, + border: `${px2rem(1)} solid ${cssVar(system.color.border.input.default)}`, + backgroundColor: system.color.bg.default, + borderRadius: system.shape.x1, boxSizing: 'border-box', - height: 40, + height: system.space.x10, transition: '0.2s box-shadow, 0.2s border-color', - padding: space.xxs, // Compensate for border - margin: 0, // Fix Safari + padding: system.space.x2, // Compensate for border + margin: px2rem(0), // Fix Safari + width: cssVar(width), + minWidth: cssVar(width, calc.add(calc.multiply(system.space.x20, 3), system.space.x10)), + color: system.color.text.default, + '::-ms-clear': { + display: 'none', + }, '&::placeholder': { - color: inputColors.placeholder, + color: system.color.text.hint, }, '&:hover, &.hover': { - borderColor: inputColors.hoverBorder, + borderColor: system.color.border.input.strong, }, - '&:focus-visible:not([disabled]), &.focus:not([disabled]), &:focus:not([disabled])': { - borderColor: inputColors.focusBorder, - boxShadow: `inset 0 0 0 1px ${inputColors.focusBorder}`, + '&:focus-visible:not([disabled]), &.focus:not([disabled])': { + borderColor: brand.common.focusOutline, + boxShadow: `inset 0 0 0 1px ${cssVar(brand.common.focusOutline)}`, outline: 'none', }, - '&:disabled': { - backgroundColor: inputColors.disabled.background, - borderColor: inputColors.disabled.border, - color: inputColors.disabled.text, + '&:disabled, .disabled': { + backgroundColor: system.color.bg.alt.softer, + borderColor: system.color.border.input.disabled, + color: system.color.text.disabled, '&::placeholder': { - color: inputColors.disabled.text, + color: system.color.text.disabled, }, }, - '::-ms-clear': { - display: 'none', - }, - }, - ({width}) => ({ - minWidth: width || 280, - width, }), - ({grow}) => - grow && { - width: '100%', + modifiers: { + grow: { + true: { + width: '100%', + resize: 'vertical', + }, + false: { + width: 'initial', + }, }, - ({theme, error}) => { - return { - '&:focus-visible:not([disabled]), &.focus:not([disabled])': { - borderColor: theme.canvas.palette.common.focusOutline, - boxShadow: `inset 0 0 0 1px ${theme.canvas.palette.common.focusOutline}`, - outline: 'none', + + error: { + error: { + borderColor: brand.error.base, + boxShadow: `inset 0 0 0 ${px2rem(1)} ${brand.error.base}`, + '&:hover, &.hover, &:disabled, &.disabled, &:focus-visible:not([disabled]), &.focus:not([disabled])': + { + borderColor: brand.error.base, + }, + '&:focus-visible:not([disabled]), &.focus:not([disabled])': { + boxShadow: `inset 0 0 0 ${px2rem(1)} ${brand.error.base}, 0 0 0 2px ${ + system.color.border.inverse + }, 0 0 0 4px ${brand.common.focusOutline}`, + }, + }, + alert: { + borderColor: brand.alert.darkest, + boxShadow: `inset 0 0 0 ${px2rem(2)} ${brand.alert.base}`, + '&:hover, &.hover, &:disabled, &.disabled, &:focus-visible:not([disabled]), &.focus:not([disabled])': + { + borderColor: brand.alert.darkest, + }, + + '&:focus-visible:not([disabled]), &.focus:not([disabled])': { + boxShadow: `inset 0 0 0 ${px2rem(2)} ${brand.alert.base}, + 0 0 0 2px ${system.color.border.inverse}, + 0 0 0 4px ${brand.common.focusOutline}`, + }, }, - ...errorRing(error, theme), - }; - } -); + }, + }, + defaultModifiers: { + grow: 'false', + }, +}); export const TextInput = createComponent('input')({ displayName: 'TextInput', Component: ({grow, error, width, ...elemProps}: TextInputProps, ref, Element) => ( - ), subComponents: { diff --git a/modules/react/text-input/spec/InputIconContainer.spec.tsx b/modules/react/text-input/spec/InputIconContainer.spec.tsx deleted file mode 100644 index 3fb0f2cd37..0000000000 --- a/modules/react/text-input/spec/InputIconContainer.spec.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import * as React from 'react'; -import {render} from '@testing-library/react'; - -import {SystemIcon} from '@workday/canvas-kit-react/icon'; -import {exclamationCircleIcon} from '@workday/canvas-system-icons-web'; -import {InputIconContainer} from '../lib/InputIconContainer'; - -describe('InputIconContainer', () => { - it('should render an Icon', () => { - const {container} = render( - } /> - ); - - expect(container).toContainHTML('wd-icon-exclamation'); - }); -}); diff --git a/modules/react/toast/lib/Toast.tsx b/modules/react/toast/lib/Toast.tsx index 44ebe2ea93..e92f1d6c04 100644 --- a/modules/react/toast/lib/Toast.tsx +++ b/modules/react/toast/lib/Toast.tsx @@ -1,7 +1,6 @@ import React from 'react'; import {createContainer, ExtractProps} from '@workday/canvas-kit-react/common'; -import {Flex} from '@workday/canvas-kit-react/layout'; import {Popup} from '@workday/canvas-kit-react/popup'; import {ToastCloseIcon} from './ToastCloseIcon'; @@ -10,6 +9,9 @@ import {ToastMessage} from './ToastMessage'; import {ToastLink} from './ToastLink'; import {ToastBody} from './ToastBody'; import {useToastModel} from './hooks/useToastModel'; +import {calc, createStencil} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; +import {mergeStyles} from '@workday/canvas-kit-react/layout'; export interface ToastProps extends Omit, 'model'> {} @@ -45,6 +47,16 @@ const getAriaAttributes = (mode: string, id: string): React.HtmlHTMLAttributes(({children, ...elemProps}, _, model) => { return ( {children} diff --git a/modules/react/toast/lib/ToastBody.tsx b/modules/react/toast/lib/ToastBody.tsx index 3bf7fae3e9..2c12f0c2ff 100644 --- a/modules/react/toast/lib/ToastBody.tsx +++ b/modules/react/toast/lib/ToastBody.tsx @@ -2,25 +2,29 @@ import React from 'react'; import {createComponent, ExtractProps} from '@workday/canvas-kit-react/common'; import {Popup} from '@workday/canvas-kit-react/popup'; -import {Flex} from '@workday/canvas-kit-react/layout'; +import {Flex, mergeStyles} from '@workday/canvas-kit-react/layout'; +import {createStencil} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; export interface ToastBodyProps extends ExtractProps {} +export const toastBodyStencil = createStencil({ + base: { + alignItems: 'flex-start', + flexDirection: 'column', + justifyContent: 'center', + paddingTop: system.space.x4, + paddingBottom: system.space.x4, + flexGrow: 1, + gap: system.space.x1, + }, +}); + export const ToastBody = createComponent('div')({ displayName: 'Toast.Body', Component: ({children, ...elemProps}: ToastBodyProps, ref, Element) => { return ( - + {children} ); diff --git a/modules/react/toast/lib/ToastCloseIcon.tsx b/modules/react/toast/lib/ToastCloseIcon.tsx index 4a9a984da1..8df5ee5155 100644 --- a/modules/react/toast/lib/ToastCloseIcon.tsx +++ b/modules/react/toast/lib/ToastCloseIcon.tsx @@ -1,14 +1,27 @@ import React from 'react'; import {createComponent, ExtractProps} from '@workday/canvas-kit-react/common'; import {Popup} from '@workday/canvas-kit-react/popup'; +import {createStencil} from '@workday/canvas-kit-styling'; +import {mergeStyles} from '@workday/canvas-kit-react/layout'; export interface ToastCloseIconProps extends ExtractProps {} +export const toastCloseIconStencil = createStencil({ + base: { + position: 'relative', + }, +}); + export const ToastCloseIcon = createComponent('button')({ displayName: 'Toast.CloseIcon', Component: (elemProps: ToastCloseIconProps, ref, Element) => { return ( - + ); }, }); diff --git a/modules/react/toast/lib/ToastIcon.tsx b/modules/react/toast/lib/ToastIcon.tsx index 3183b53418..a7ed61ca5f 100644 --- a/modules/react/toast/lib/ToastIcon.tsx +++ b/modules/react/toast/lib/ToastIcon.tsx @@ -2,22 +2,21 @@ import React from 'react'; import {createComponent} from '@workday/canvas-kit-react/common'; import {SystemIcon, SystemIconProps} from '@workday/canvas-kit-react/icon'; +import {createStencil, handleCsProp} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; export interface ToastIconProps extends Omit {} +export const toastIconStencil = createStencil({ + base: { + alignSelf: 'start', + margin: `${system.space.x4} ${system.space.x3}`, + }, +}); + export const ToastIcon = createComponent('div')({ displayName: 'Toast.Icon', Component: (elemProps: ToastIconProps, ref, Element) => { - return ( - - ); + return ; }, }); diff --git a/modules/react/toast/lib/ToastMessage.tsx b/modules/react/toast/lib/ToastMessage.tsx index f55f491fa8..b732a315ce 100644 --- a/modules/react/toast/lib/ToastMessage.tsx +++ b/modules/react/toast/lib/ToastMessage.tsx @@ -3,20 +3,29 @@ import React from 'react'; import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common'; import {useToastModel} from './hooks/useToastModel'; import {Subtext} from '@workday/canvas-kit-react/text'; +import {createStencil} from '@workday/canvas-kit-styling'; +import {mergeStyles} from '@workday/canvas-kit-react/layout'; +import {system} from '@workday/canvas-tokens-web'; export interface ToastMessageProps extends Omit, 'size'> {} +export const toastMessageStencil = createStencil({ + base: { + wordBreak: 'break-word', + marginBlockStart: system.space.zero, + marginBlockEnd: system.space.zero, + }, +}); + export const ToastMessage = createSubcomponent('p')({ modelHook: useToastModel, })(({children, ...elemProps}, Element, model) => { return ( {children}